Take the following steps to start a project:
Start Visual Studio .NET.
Choose File->New->Project… from the menu.
In the New Project dialog box, choose either "Visual C# Projects" or "VB Projects" in the Projects Type List, and choose "Windows Application" in the Templates List.
Type the project name as "TwainDuplex" in the Project Name field, and then choose OK. If desired, type a new location for your project or select a directory using the Browse button, and then choose OK.
In the "Solution Explorer" window, right-click on the "References" folder, and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and browse to Leadtools For .NET "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet\Win32" folder and select the following DLLs:
Click the Select button and then press the OK button to add the above DLLs to the application.
Text | Name |
Acquire | buttonAcquire |
Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code ) and add the following lines at the beginning of the file:
Imports Leadtools
Imports Leadtools.Twain
Imports Leadtools.Codecs
Imports Leadtools.WinForms
using Leadtools;
using Leadtools.Twain;
using Leadtools.Codecs;
using Leadtools.WinForms;
Declare the following private variable:
Private WithEvents twnSession As TwainSession
private TwainSession twnSession;
Add an event handler to the Form1 Load event and code it as follows:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
' Unlock Document support.
' Note that this is a sample key, which will not work in your toolkit.
Dim MY_LICENSE_FILE As String = "d:\temp\TestLic.lic"
Dim MY_DEVELOPER_KEY As String = "xyz123abc"
RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DEVELOPER_KEY)
twnSession = new TwainSession
twnSession.Startup(Me.Handle, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
private void Form1_Load(object sender, System.EventArgs e)
{
try
{
// Unlock Document support.
// Note that this is a sample key, which will not work in your toolkit.
string MY_LICENSE_FILE = "d:\\temp\\TestLic.lic";
string MY_DEVELOPER_KEY = "xyz123abc";
RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DEVELOPER_KEY);
twnSession = new TwainSession();
twnSession.Startup(this.Handle, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None);
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message);
}
}
Add an event handler to the Form1 Closing event and code it as follows:
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Try
twnSession.Shutdown()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
twnSession.Shutdown();
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message);
}
}
Add an event handler to the buttonAcquire Click event and code it as follows:
Private Sub buttonAcquire_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonAcquire.Click
Dim twainCap As TwainCapability
twnSession.SelectSource(String.Empty)
Try
twainCap = twnSession.GetCapability(TwainCapabilityType.Duplex, TwainGetCapabilityMode.GetValues)
If Not IsNothing(twainCap) Then
' check if the selected driver supports duplex capability
If (twainCap.OneValueCapability.ItemType <> TwainItemType.Uint16) Then
twnSession.Shutdown()
Return
End If
Dim item As TwainCapabilityValue = CType(twainCap.OneValueCapability.Value, TwainCapabilityValue)
Select Case item
Case TwainCapabilityValue.DuplexNone
MessageBox.Show(Me, "Duplex capability is not supported in the selected driver")
Case TwainCapabilityValue.DuplexOnePassDuplex
MessageBox.Show(Me, "1 Pass Duplex capability is supported in the selected driver")
Case TwainCapabilityValue.DuplexTwoPassDuplex
MessageBox.Show(Me, "2 Pass Duplex capability is supported in the selected driver")
End Select
' make sure the duplex capability is enabled
If item <> TwainCapabilityValue.DuplexNone Then
Dim enable As Boolean = True
twainCap.Information.Type = TwainCapabilityType.DuplexEnabled
twainCap.Information.ContainerType = TwainContainerType.OneValue
twainCap.OneValueCapability.ItemType = TwainItemType.Bool
twainCap.OneValueCapability.Value = CType(enable, Object)
twnSession.SetCapability(twainCap, TwainSetCapabilityMode.Set)
MessageBox.Show(Me, "The duplex capability is enabled")
End If
End If
Catch ex As Exception
MessageBox.Show(Me, ex.Message)
End Try
' try to acquire pages using duplex capability
twnSession.Acquire(TwainUserInterfaceFlags.Show Or TwainUserInterfaceFlags.Modal)
End Sub
private void buttonAcquire_Click(object sender, System.EventArgs e)
{
TwainCapability twainCap;
twnSession.SelectSource(string.Empty);
try
{
twainCap = twnSession.GetCapability(TwainCapabilityType.Duplex, TwainGetCapabilityMode.GetValues);
if (twainCap != null)
{
// check if the selected driver supports duplex capability
if (twainCap.OneValueCapability.ItemType != TwainItemType.Uint16)
{
twnSession.Shutdown();
return;
}
TwainCapabilityValue item = (TwainCapabilityValue)twainCap.OneValueCapability.Value;
switch (item)
{
case TwainCapabilityValue.DuplexNone:
MessageBox.Show(this, "Duplex capability is not supported in the selected driver");
break;
case TwainCapabilityValue.DuplexOnePassDuplex:
MessageBox.Show(this, "1 Pass Duplex capability is supported in the selected driver");
break;
case TwainCapabilityValue.DuplexTwoPassDuplex:
MessageBox.Show(this, "2 Pass Duplex capability is supported in the selected driver");
break;
}
// make sure the duplex capability is enabled
if (item != TwainCapabilityValue.DuplexNone)
{
bool enable = true;
twainCap.Information.Type = TwainCapabilityType.DuplexEnabled;
twainCap.Information.ContainerType = TwainContainerType.OneValue;
twainCap.OneValueCapability.ItemType = TwainItemType.Bool;
twainCap.OneValueCapability.Value = enable;
twnSession.SetCapability(twainCap, TwainSetCapabilityMode.Set);
MessageBox.Show(this, "The duplex capability is enabled");
}
}
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message);
}
// try to acquire pages using duplex capability
twnSession.Acquire(TwainUserInterfaceFlags.Show | TwainUserInterfaceFlags.Modal);
}
|
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.