Working with Automated Annotations in Windows Forms

Take the following steps to start a project and to add some code that will demonstrate the automated annotation features of the LEADTOOLS Windows Forms Annotations.

  1. Start Visual Studio.
  2. Choose File->New->Project? from the menu.
  3. In the New Project dialog box, choose "Visual C#" and "Windows Forms Application" as the project template.
  4. Type the project name as "WinForms Automation" 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 for the project and select "Add Reference..." from the context menu. In the "Reference Manager" dialog box, select Browse to the "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet4\" folder (depending on your target platform), and select the following assembly files:

    • Leadtools.dll
    • Leadtools.Codecs.dll
    • Leadtools.Drawing.dll
    • Leadtools.Controls.WinForms.dll
    • Leadtools.Codecs.Bmp.dll
    • Leadtools.Codecs.Fax.dll
    • Leadtools.Codecs.Tif.dll
    • Leadtools.Codecs.Cmp.dll
    • Leadtools.Codecs.Png.dll
    • Leadtools.Annotations.Engine.dll
    • Leadtools.Annotations.Designers.dll
    • Leadtools.Annotations.Rendering.WinForms.dll
    • Leadtools.Annotations.Automation.dll
    • Leadtools.Annotations.WinForms.dll

    Click the Select button and then press the OK button to add the above references to the application.

    Note: Leadtools.Annotations.WinForms.dll is the result of compiling the example project shipped with source code at <LEADTOOLS_INSTALLDIR>\Examples\DotNet\CS\Leadtools.Annotations.WinForms. The LEADTOOLS setup copies a precompiled version of this assembly into the Bin\DotNet4 folder. This assembly contains .NET WinForms annotations automation user-interface helper classes such as AnnAutomationRasterImageViewer and AnnAutomationManagerHelper.

  6. If you are using .NET 4, then this application will required switching the Target framework to full .NET Framework 4.

  7. Switch to code view of the main form and add the following declarations at the top:

    using Leadtools; 
    using Leadtools.Controls; 
    using Leadtools.Codecs; 
    using Leadtools.Annotations.Engine; 
    using Leadtools.Annotations.Designers; 
    using Leadtools.Annotations.Rendering; 
    using Leadtools.Annotations.Automation; 
    using Leadtools.Annotations.WinForms; 

  8. Add the following private members to Form1:

    // Annotations-aware ImageViewer 
    private AutomationImageViewer _imageViewer; 
    // Annotations automation manager with WinForms functionality 
    private AutomationManagerHelper _annotations; 

  9. Add the following code to in Form1 Load event. This will create a minimum automation application:

    protected override void OnLoad(EventArgs e) 
             // Create the viewer and add it to the form  
             _imageViewer = new AutomationImageViewer(); 
             _imageViewer.Dock = DockStyle.Fill; 
             // Create the annotations  
             AnnAutomationManager automationManager = new AnnAutomationManager(); 
             // Create the helper  
             _annotations = new AutomationManagerHelper(automationManager); 
             // Create the toolbar and add it to our form  
             ToolBar toolBar = _annotations.ToolBar; 
             toolBar.Dock = DockStyle.Top; 
             toolBar.Appearance = ToolBarAppearance.Flat; 
             // Load an image into the viewer  
             using (RasterCodecs codecs = new RasterCodecs()) 
                _imageViewer.Image = codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\sample1.cmp"); 
             // Create an automation object for it  
             AnnAutomation automation = new AnnAutomation(automationManager, _imageViewer); 
             // Set the container size 
             automation.Container.Size = automation.Container.Mapper.SizeToContainerCoordinates(LeadSizeD.Create(_imageViewer.Image.ImageWidth, _imageViewer.Image.ImageHeight)); 
             // Create automation interactive mode to create and manipulate the annotations 
             AutomationInteractiveMode automationInteractiveMode = new AutomationInteractiveMode(); 
             automationInteractiveMode.AutomationControl = _imageViewer; 
             automationInteractiveMode.IsEnabled = true; 
             // Add the events to show the object context menu and object properties form  
             automation.OnShowContextMenu += delegate(object sender, AnnAutomationEventArgs showContextMenuEventArgs) 
                if (showContextMenuEventArgs != null && showContextMenuEventArgs.Object != null) 
                   AnnAutomationObject automationObject = showContextMenuEventArgs.Object; 
                   if (automationObject != null && automationObject.ContextMenu != null) 
                      ObjectContextMenu menu = automationObject.ContextMenu as ObjectContextMenu; 
                      if (menu != null) 
                         menu.Automation = sender as AnnAutomation; 
                         menu.Show(this, _imageViewer.PointToClient(Cursor.Position)); 
             automation.OnShowObjectProperties += delegate(object sender, AnnAutomationEventArgs showObjectPropertiesEventArgs) 
                // Show the object properties form  
                using (AutomationUpdateObjectDialog form = new AutomationUpdateObjectDialog()) 
                      form.Automation = automation; 
                   catch (Exception ex) 
                      MessageBox.Show(this, ex.Message); 
             // Set it as Active so UI input will go to it  
             automation.Active = true; 

  10. Build and run the demo. You should be able to annotate the image, right click on any object to show the context menu, select properties to change any object properties.
Help Version 20.0.2020.4.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Imaging, Medical, and Document