LEADTOOLS For .NET Class Library Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.28
Working with Automated Annotation
Take 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 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 "Working With Automated Annotations" 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 the "<LEADTOOLS_INSTALLDIR>\Bin\DotNet\Win32 " folder and select the following DLLs:
    • Leadtools.dll
    • Leadtools.Annotations.dll
    • Leadtools.Codecs.dll
    • Leadtools.Codecs.Cmp.dll
    • Leadtools.WinForms.dll
  6. Click the Select button and then press the OK button to add the above DLLs to the application. Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and Drag and drop an instance of RasterImageViewer to the form. If you do not have RasterImageViewer in your toolbox, select Tools->Add Remove Toolbox Items from the menu. Click Browse and then select Leadtools.WinForms.DLL from the "\LEAD Technologies\LEADTOOLS 17\Bin\DotNet\Win32" folder and then click Open and then click OK.
  7. Go to the toolbox (View->Toolbox) and Drag and drop 2 instances of RadioButton control to the bottom of the form, and set the following properties for them:
    Text Name Checked
    Design Mode radioButton1 True
    Run Mode radioButton2 False
  8. 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.Annotations
                Imports Leadtools.Codecs
                Imports Leadtools.WinForms
                
    
    [C#]
                 
                using Leadtools;
                using Leadtools.Annotations;
                using Leadtools.Codecs;
                using Leadtools.WinForms;
                
    
  9. Declare the following private variable:

    [Visual Basic]

                 
                ' Automation Manager used in managing the automation mode.
                Private annAutomationManager As AnnAutomationManager
                
    
    [C#]
                 
                // Automation Manager used in managing the automation mode.
                private AnnAutomationManager annAutomationManager;
                
    
  10. Add an event handler to the Form1 Load event and code it as follows:

    [Visual Basic]

                 
                Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
                   ' intitialize a new RasterCodecs object
                   Dim codecs As New RasterCodecs()
                   ' load the main image into our viewer
                   rasterImageViewer1.Image = codecs.Load("C:\Users\Public\Documents\LEADTOOLS Images\Sample1.cmp")
                   
                   If (Not IsNothing(RasterImageViewer1.Image)) Then
                      ' create and setup the automation manager
                      annAutomationManager = New AnnAutomationManager
                      
                      ' Instruct the manager to create the default (all) automation objects.
                      annAutomationManager.CreateDefaultObjects()
                      
                      ' create the toolbar and add it to the form
                      annAutomationManager.CreateToolBar()
                      Controls.Add(annAutomationManager.ToolBar)
                      
                      ' setup the automation (will create the container as well)
                      Dim automation As AnnAutomation = New AnnAutomation(annAutomationManager, RasterImageViewer1)
                      
                      ' setup this automation as the active one
                      automation.Active = True
                   End If
                End Sub
                
    
    [C#]
                 
                private void Form1_Load(object sender, System.EventArgs e)
                {
                   // intitialize a new RasterCodecs object
                   RasterCodecs codecs = new RasterCodecs();
                   // load the main image into our viewer
                   rasterImageViewer1.Image = codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\Sample1.cmp");
                   
                   if(rasterImageViewer1.Image != null)
                   {
                      // create and setup the automation manager
                      annAutomationManager = new AnnAutomationManager();
                      
                      // Instruct the manager to create the default (all) automation objects.
                      annAutomationManager.CreateDefaultObjects();
                      
                      // create the toolbar and add it to the form
                      annAutomationManager.CreateToolBar();
                      Controls.Add(annAutomationManager.ToolBar);
                      
                      // setup the automation (will create the container as well)
                      AnnAutomation automation = new AnnAutomation(annAutomationManager, rasterImageViewer1);
                      
                      // add an event handler for changes to the current designer
                      automation.CurrentDesignerChanged += new EventHandler(automation_CurrentDesignerChanged);
                      
                      // setup this automation as the active one
                      automation.Active = true;
                   }
                }
                
    
  11. Add an event handler to the radioButton1 CheckedChanged event and code it as follows:

    [Visual Basic]

                 
                Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
                   UserModeChanged(sender)
                End Sub   
                
    
    [C#]
                 
                private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
                {
                   UserModeChanged(sender);
                }
                
    
  12. Add an event handler to the radioButton2 CheckedChanged event and code it as follows:

    [Visual Basic]

                 
                Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
                   UserModeChanged(sender)
                End Sub   
                
    
    [C#]
                 
                private void radioButton2_CheckedChanged(object sender, System.EventArgs e)
                {
                   UserModeChanged(sender);
                }
                
    
  13. Add the following function code to class Form1:

    [Visual Basic]

                 
                Private Sub UserModeChanged(ByVal sender As Object)
                   If (Not IsNothing(annAutomationManager)) Then
                      If (sender Is radioButton1) Then
                         annAutomationManager.UserMode = AnnUserMode.Design
                      Else
                         annAutomationManager.UserMode = AnnUserMode.Run
                      End If
                   End If
                End Sub
                
    
    [C#]
                 
                private void UserModeChanged(object sender)
                {
                   annAutomationManager.UserMode = (sender == radioButton1)?AnnUserMode.Design: AnnUserMode.Run;
                }
                
    
  14. Add the following function code to class Form1:

    [Visual Basic]

                ' if the current designer is a button run designer, add a handler for Run
                Private Sub automation_CurrentDesignerChanged(ByVal sender As Object, ByVal e As EventArgs)
                   Dim automation As AnnAutomation = DirectCast(sender, AnnAutomation)
                   If (TypeOf (automation.CurrentDesigner) Is AnnButtonRunDesigner) Then
                      Dim buttonRunDesigner As AnnButtonRunDesigner = DirectCast(automation.CurrentDesigner, AnnButtonRunDesigner)
                      AddHandler buttonRunDesigner.Run, AddressOf buttonRunDesigner_Run
                   End If
                End Sub
                Private Sub buttonRunDesigner_Run(ByVal sender As Object, ByVal e As AnnRunDesignerEventArgs)
                   If (e.OperationStatus = AnnDesignerOperationStatus.End) Then
                      Dim btn As AnnButtonObject = DirectCast(e.Object, AnnButtonObject)
                      MessageBox.Show(String.Format("Button with text = {0} was clicked!", btn.Text))
                   End If
                End Sub
                
    
    [C#]
                // if the current designer is a button run designer, add a handler for Run
                private void automation_CurrentDesignerChanged(object sender, EventArgs e)
                {
                   AnnAutomation automation = sender as AnnAutomation;
                   AnnButtonRunDesigner buttonRunDesigner = automation.CurrentDesigner as AnnButtonRunDesigner;
                   if(buttonRunDesigner != null)
                      buttonRunDesigner.Run += new EventHandler<AnnRunDesignerEventArgs>(buttonRunDesigner_Run);
                }
                private void buttonRunDesigner_Run(object sender, AnnRunDesignerEventArgs e)
                {
                   if(e.OperationStatus == AnnDesignerOperationStatus.End)
                   {
                      AnnButtonObject btn = e.Object as AnnButtonObject;
                      MessageBox.Show(string.Format("Button with text = {0} was clicked!", btn.Text)); 
                   }
                }
                
    
  15. Build, and Run the program to test it. You can now select objects from the toolbar, draw objects on top of the image, select the objects and move/change them. Right-click on any object to show its properties, etc.

    Create an audio annotation. Right-click on the annotation and set the file to any .wav file available on your system. Create a button annotation. Right-click on the annotation and change any of the button properties you wish. Select Run Mode Radio button. As you move the cursor over the audio annotation and the button annotation, the cursor changes to a hand. Click on the audio annotation to hear the .wav file. Click on the button annotation to call the program listed in the Hyperlink field.