Take the following steps to start a project:
Start Visual Studio.
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 "TwainFeeder2" 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.
Go to the toolbox (View->Toolbox) and Drag and drop a 1 instance of Button control to the top of the form and set the following properties for them:
| 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 LeadtoolsImports Leadtools.TwainImports Leadtools.CodecsImports 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.LoadTry' 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 TwainSessiontwnSession.Startup(Me.Handle, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None)Catch ex As ExceptionMessageBox.Show(ex.Message)End TryEnd 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.FormClosingTrytwnSession.Shutdown()Catch ex As ExceptionMessageBox.Show(ex.Message)End TryEnd 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.ClickDim twainCap As TwainCapability = New TwainCapabilitytwnSession.SelectSource(String.Empty)TrytwainCap.Information.Type = TwainCapabilityType.FeederEnabledtwainCap.Information.ContainerType = TwainContainerType.OneValueDim enable As Boolean = TruetwainCap.OneValueCapability.ItemType = TwainItemType.BooltwainCap.OneValueCapability.Value = enabletwnSession.SetCapability(twainCap, TwainSetCapabilityMode.Set)MessageBox.Show(Me, "CAP_FEEDERENABLED capability is enabled")' check if there is document loaded in the feedertwainCap = twnSession.GetCapability(TwainCapabilityType.FeederLoaded, TwainGetCapabilityMode.GetValues)' check if the selected driver supports duplex capabilityenable = CType(twainCap.OneValueCapability.Value, Boolean)If enable ThenMessageBox.Show(Me, "There is document loaded in the feeder")ElseMessageBox.Show(Me, "There is no document loaded in the feeder")End IfCatch ex As ExceptionMessageBox.Show(Me, ex.Message)End Try' try to acquire pages using CAP_FEEDERENABLED and CAP_FEEDERLOADED capabilitiestwnSession.Acquire(TwainUserInterfaceFlags.Show Or TwainUserInterfaceFlags.Modal)End Sub
private void buttonAcquire_Click(object sender, System.EventArgs e){TwainCapability twainCap = new TwainCapability();twnSession.SelectSource(string.Empty);try{twainCap.Information.Type = TwainCapabilityType.FeederEnabled;twainCap.Information.ContainerType = TwainContainerType.OneValue;bool enable = true;twainCap.OneValueCapability.ItemType = TwainItemType.Bool;twainCap.OneValueCapability.Value = enable;twnSession.SetCapability(twainCap, TwainSetCapabilityMode.Set);MessageBox.Show(this, "CAP_FEEDERENABLED capability is enabled");// check if there is document loaded in the feedertwainCap = twnSession.GetCapability(TwainCapabilityType.FeederLoaded, TwainGetCapabilityMode.GetValues);// check if the selected driver supports duplex capabilityenable = (bool)twainCap.OneValueCapability.Value;if (enable)MessageBox.Show(this, "There is document loaded in the feeder");elseMessageBox.Show(this, "There is no document loaded in the feeder");}catch (Exception ex){MessageBox.Show(this, ex.Message);}// try to acquire pages using CAP_FEEDERENABLED and CAP_FEEDERLOADED capabilitiestwnSession.Acquire(TwainUserInterfaceFlags.Show | TwainUserInterfaceFlags.Modal);}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
