LEADTOOLS For .NET Class Library Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.28
Twain Feeder Tutorial # 1
ScanTutorials Take the following steps to start a project:
  1. Start Visual Studio .NET.
  2. Choose File->New->Project… from the menu.
  3. In the New Project dialog box, choose either "Visual C# Projects" or "Visual Basic Projects" in the Projects Type List, and choose "Windows Application " in the Templates List.
  4. Type the project name as "GetFastTwainScan" 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 .
  5. 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:
    • Leadtools.dll
    • Leadtools.Twain.dll
    • Leadtools.Codecs.dll
    • Leadtools.WinForms.dll
    Click the Select button and then press the OK button to add the above DLLs to the application.
  6. 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
  7. 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:

    [Visual Basic]

     
                 Imports Leadtools
                 Imports Leadtools.Twain
                 Imports Leadtools.Codecs
                 Imports Leadtools.WinForms
                 
    
    [C#]
     
                 using Leadtools;
                 using Leadtools.Twain;
                 using Leadtools.Codecs;
                 using Leadtools.WinForms;
                 
    
  8. Declare the following private variable:

    [Visual Basic]

     
                 Private WithEvents twnSession As TwainSession
                 
    
    [C#]
     
                 private TwainSession twnSession;
                 
    
  9. Add an event handler to the Form1 Load event and code it as follows:

    [Visual Basic]

                 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.
                       RasterSupport.Unlock(RasterSupportType.Document, "TestKey")
                 
                       twnSession = new TwainSession
                       twnSession.Startup(Me, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None)
                    Catch ex As Exception
                       MessageBox.Show(ex.Message)
                    End Try
                 End Sub   
                 
    
    [C#]
                 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.
                       RasterSupport.Unlock(RasterSupportType.Document, "TestKey");
                 
                       twnSession = new TwainSession();
                       twnSession.Startup(this, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None);
                    }
                    catch (Exception ex)
                    {
                       MessageBox.Show(this, ex.Message);
                    }
                 }
                 
    
  10. Add an event handler to the Form1 Closing event and code it as follows:

    [Visual Basic]

                 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   
                 
    
    [C#]
     
                 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
                 {
                    try
                    {
                       twnSession.Shutdown();
                    }
                    catch (Exception ex)
                    {
                       MessageBox.Show(this, ex.Message);
                    }
                 }
                 
    
  11. Add an event handler to the buttonAcquire Click event and code it as follows:

    [Visual Basic]

                 Private Sub buttonAcquire_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonAcquire.Click
                    Dim twainCap As TwainCapability = New TwainCapability
                
                    twnSession.SelectSource(String.Empty)
                
                    Try
                       twainCap.Information.Type = TwainCapabilityType.AutoFeed
                       twainCap.Information.ContainerType = TwainContainerType.OneValue
                
                       Dim enable As Boolean = True
                
                       twainCap.OneValueCapability.ItemType = TwainItemType.Bool
                       twainCap.OneValueCapability.Value = enable
                
                       twnSession.SetCapability(twainCap, TwainSetCapabilityMode.Set)
                       MessageBox.Show(Me, "AutoFeed capability is enabled")
                    Catch ex As Exception
                       MessageBox.Show(Me, ex.Message)
                    End Try
                
                    ' try to acquire pages using AutoFeed capability
                    twnSession.Acquire(TwainUserInterfaceFlags.Show Or TwainUserInterfaceFlags.Modal)
                 End Sub
                 
    
    [C#]
                 private void buttonAcquire_Click(object sender, System.EventArgs e)
                 {
                    TwainCapability twainCap = new TwainCapability();
                    twnSession.SelectSource(string.Empty);
                    
                    try
                    {
                       twainCap.Information.Type = TwainCapabilityType.AutoFeed;
                       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, "AutoFeed capability is enabled");
                    }
                    catch (Exception ex)
                    {
                       MessageBox.Show(this, ex.Message);
                    }
                    
                    // try to acquire pages using AutoFeed capability
                    twnSession.Acquire(TwainUserInterfaceFlags.Show | TwainUserInterfaceFlags.Modal);
                 }
                 
    
  12. Build, and Run the program to test it.