mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:59:23 +08:00
Tweak double buffer use in sample.
This commit is contained in:
parent
ebe277e614
commit
0a7ff8b140
@ -10,12 +10,10 @@ namespace WinFormSample
|
||||
{
|
||||
static class ControlExtensions
|
||||
{
|
||||
public static void SetDoubleBuffered(this Control control, bool value)
|
||||
public static void SetDoubleBufferedAsNeeded(this Control control)
|
||||
{
|
||||
if (SystemInformation.TerminalServerSession) return;
|
||||
|
||||
var dbprop = control.GetType().GetProperty("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
dbprop!.SetValue(control, value);
|
||||
dbprop!.SetValue(control, !SystemInformation.TerminalServerSession);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
using Microsoft.Win32;
|
||||
using NTwain;
|
||||
using NTwain.Data;
|
||||
using System;
|
||||
@ -34,7 +35,8 @@ namespace WinFormSample
|
||||
twain.TransferError += Twain_TransferError;
|
||||
twain.DeviceEvent += Twain_DeviceEvent;
|
||||
|
||||
capListView.SetDoubleBuffered(true);
|
||||
capListView.SetDoubleBufferedAsNeeded();
|
||||
SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;
|
||||
|
||||
saveFolder = Path.Combine(Path.GetTempPath(), "ntwain-sample");
|
||||
Directory.CreateDirectory(saveFolder);
|
||||
@ -42,6 +44,18 @@ namespace WinFormSample
|
||||
this.Disposed += Form1_Disposed;
|
||||
}
|
||||
|
||||
private void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
|
||||
{
|
||||
switch (e.Reason)
|
||||
{
|
||||
case SessionSwitchReason.RemoteConnect:
|
||||
case SessionSwitchReason.SessionUnlock:
|
||||
case SessionSwitchReason.SessionLogon:
|
||||
capListView.SetDoubleBufferedAsNeeded();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnHandleCreated(EventArgs e)
|
||||
{
|
||||
base.OnHandleCreated(e);
|
||||
@ -88,7 +102,7 @@ namespace WinFormSample
|
||||
|
||||
private void Twain_DataTransferred(TwainAppSession sender, DataTransferredEventArgs e)
|
||||
{
|
||||
Debug.WriteLine($"[thread {Environment.CurrentManagedThreadId}] data transferred with info {e.ImageInfo}");
|
||||
Debug.WriteLine($"[thread {Environment.CurrentManagedThreadId}] data transferred with info {e.GetImageInfo()}");
|
||||
if (e.Data == null) return;
|
||||
using (var stream = new MemoryStream(e.Data))
|
||||
using (var img = Image.FromStream(stream))
|
||||
@ -116,7 +130,7 @@ namespace WinFormSample
|
||||
|
||||
private void Twain_CurrentSourceChanged(TwainAppSession sender, TW_IDENTITY_LEGACY ds)
|
||||
{
|
||||
lblCurrent.Text = ds.ProductName;
|
||||
lblCurrent.Text = ds.ToString();
|
||||
if (twain.State == STATE.S4)
|
||||
{
|
||||
LoadCapInfoList();
|
||||
@ -291,7 +305,7 @@ namespace WinFormSample
|
||||
|
||||
private void btnStart_Click(object sender, EventArgs e)
|
||||
{
|
||||
twain.EnableSource(true, false);
|
||||
twain.EnableSource(false, false);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user