Working with Automated Annotations

Perform the following steps to create and run a program that implements Automated Annotations:

  1. Start Visual Studio .NET.
  2. Choose File->New->Project… from the main menu.
  3. In the New Project dialog box, select either "Visual C# " or "VB " in the Installed Templates List, and choose "Windows Forms Application " in the Templates List.
  4. Type the project name as "Working With Automated Annotations" in the Name field, and then click OK. If desired, type a new location for your project or select a directory using the Browse button, and then click OK.
  5. In the "Solution Explorer" window, right-click the "References" folder, and choose "Add Reference…" from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and browse to the "<LEADTOOLS_INSTALLDIR>\Bin\DotNet4\Win32 " folder and select the following DLLs:

    • Leadtools.dll
    • Leadtools.Annotations.Core.dll
    • Leadtools.Annotations.Rendering.WinForms.dll
    • Leadtools.Annotations.Designers.dll
    • Leadtools.Annotations.Automation.dll
    • Leadtools.Annotations.WinForms.dll
    • Leadtools.Codecs.dll
    • Leadtools.Codecs.Cmp.dll
    • Leadtools.Controls.WinForms.dll
  6. Click Add and then click OK to add the above DLLs to the application.

  7. Switch to Form1 code view (right-click Form1 in the Solution Explorer and then choose View Code) and add the following lines at the beginning of the file:

    VB
                       
    Imports Leadtools 
    Imports Leadtools.Annotations.Core 
    Imports Leadtools.Annotations.Designers 
    Imports Leadtools.Annotations.Automation 
    Imports Leadtools.Codecs 
    Imports Leadtools.Controls 
    Imports Leadtools.Annotations.WinForms 
                      
         

    C#
                       
    using Leadtools; 
    using Leadtools.Annotations.Core; 
    using Leadtools.Annotations.Designers; 
    using Leadtools.Annotations.Automation; 
    using Leadtools.Codecs; 
    using Leadtools.Controls; 
    using Leadtools.Annotations.WinForms; 
                      
         

  8. Declare the following private variables:

    VB
    Private automationControl As ImageViewerAutomationControl 
    Private viewer As ImageViewer 
    ' The Automation Manager is used to manage the automation mode. 
    Private annAutomationManager As AnnAutomationManager 
    Private WithEvents automation As AnnAutomation 
                      
         

    C#
    private ImageViewer viewer; 
    private ImageViewerAutomationControl automationControl; 
    // The Automation Manager is used to manage the automation mode. 
    private AnnAutomationManager annAutomationManager; 
    private AnnAutomation automation; 
                      
         

  9. Add an event handler to the Form1 Load event and code it as follows:

    VB
                       
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load 
         viewer = New ImageViewer() 
         viewer.Dock = DockStyle.Fill 
                     
         automationControl = New ImageViewerAutomationControl() 
         automationControl.ImageViewer = viewer 
                     
         ' initialize a new RasterCodecs object 
         Dim codecs As New RasterCodecs() 
         ' load the main image into the viewer 
         viewer.Image = codecs.Load("C:\Users\Public\Documents\LEADTOOLS Images\Sample1.cmp") 
                     
         'initialize the interactive mode for the viewer 
         Dim automationInteractiveMode As AutomationInteractiveMode = New AutomationInteractiveMode() 
         automationInteractiveMode.AutomationControl = automationControl 
                     
         'add the interactive mode to the viewer 
         viewer.InteractiveModes.BeginUpdate() 
         viewer.InteractiveModes.Add(automationInteractiveMode) 
         viewer.InteractiveModes.EndUpdate() 
                     
         If(Not IsNothing(viewer.Image)) Then 
            ' create and set up the automation manager 
            annAutomationManager = New AnnAutomationManager 
            annAutomationManager.RestrictDesigners = True 
                     
            ' Instruct the manager to create all of the default automation objects. 
            annAutomationManager.CreateDefaultObjects() 
            Dim managerHelper As AutomationManagerHelper = New AutomationManagerHelper(annAutomationManager) 
            managerHelper.CreateToolBar() 
            Controls.Add(managerHelper.ToolBar) 
            Controls.Add(viewer) 
                     
            ' set up the automation (it will create the container as well) 
            automation = New AnnAutomation(annAutomationManager, automationControl) 
            ' set this automation as the active one 
            automation.Active = True 
                     
            automation.Container.Size = automation.Container.Mapper.SizeToContainerCoordinates(LeadSizeD.Create(viewer.Image.ImageWidth, viewer.Image.ImageHeight)) 
         End If 
    End Sub 
                      
         

    C#
                       
    private void Form1_Load(object sender, System.EventArgs e) 
    { 
      viewer = new ImageViewer(); 
      viewer.Dock = DockStyle.Fill; 
                     
      automationControl = new ImageViewerAutomationControl(); 
      automationControl.ImageViewer = viewer; 
                      
      // initialize a new RasterCodecs object 
      RasterCodecs codecs = new RasterCodecs(); 
      // load the main image into the viewer 
      viewer.Image = codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\Sample1.cmp"); 
                      
      // initialize the interactive mode for the viewer 
      AutomationInteractiveMode automationInteractiveMode = new AutomationInteractiveMode(); 
      automationInteractiveMode.AutomationControl = automationControl; 
                      
      // add the interactive mode to the viewer 
      viewer.InteractiveModes.BeginUpdate(); 
      viewer.InteractiveModes.Add(automationInteractiveMode); 
      viewer.InteractiveModes.EndUpdate(); 
                      
      if (viewer.Image != null) 
      { 
      // create and set up the automation manager 
      annAutomationManager = new AnnAutomationManager(); 
      annAutomationManager.RestrictDesigners = true; 
                      
      // Instruct the manager to create all of the default automation objects. 
      annAutomationManager.CreateDefaultObjects(); 
                      
      // initialize the manager helper and create the toolbar and add it then the viewer to the controls 
      AutomationManagerHelper managerHelper = new AutomationManagerHelper(annAutomationManager); 
      managerHelper.CreateToolBar(); 
      Controls.Add(managerHelper.ToolBar); 
      Controls.Add(viewer); 
                      
      // set up the automation (it will create the container as well) 
      automation = new AnnAutomation(annAutomationManager, automationControl); 
      // set this automation as the active one 
      automation.Active = true; 
                      
      //set the size of the container to the size of the viewer 
      automation.Container.Size = automation.Container.Mapper.SizeToContainerCoordinates(LeadSizeD.Create(viewer.Image.ImageWidth, viewer.Image.ImageHeight)); 
       } 
    } 
                      
         

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Imaging, Medical, and Document