Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
Working with WPF 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" - NET Framework 3.0 or "Visual Basic Projects" - NET Framework 3.0 in the Projects Type List, and choose "Windows Application (WPF) " 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 (For a VB project, right-click on the project file in solution explorer), and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and browse to Leadtools For .NET "\LEAD Technologies\LEADTOOLS 16.5\Bin\DotNet\Win32 " folder and select the following DLLs:
    • Leadtools.Windows.Annotations.dll
    • Leadtools.Windows.Controls.dll
    • Leadtools.Windows.Media.Transitions.dll
    Click the Select button and then press the OK button to add the above DLLs to the application.
  6. Open Window1.xaml file and replace it by the following:

    [Visual Basic]

    
    <Window x:Class="Window1"
                   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                   Title="Working_With_Automated_Annotations" Height="300" Width="300"
                   Loaded="WindowLoaded"
                   xmlns:Leadtools_Windows_Controls="clr-namespace:Leadtools.Windows.Controls;assembly=Leadtools.Windows.Controls"
            >
       <DockPanel>
          <StackPanel DockPanel.Dock="Top">
             <RadioButton Name="rbDesignMode" GroupName="UserMode" Content="Design Mode" IsChecked="True" Checked="CheckedChanged"/>
             <RadioButton Name="rbRunMode" GroupName="UserMode" Content="Run Mode" Checked="CheckedChanged"/>
          </StackPanel>
          <ToolBarTray Name="toolbarTray" DockPanel.Dock="Right" Orientation="Vertical"/>
          <Leadtools_Windows_Controls:BitmapSourceViewer x:Name="imageViewer1" Width="NaN" Height="NaN"/>
       </DockPanel>
    </Window>
    
    [C#]
    
    <Window x:Class="Working_With_Automated_Annotations.Window1"
                   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                   Title="Working_With_Automated_Annotations" Height="300" Width="300"
                   Loaded="WindowLoaded"
                   xmlns:Leadtools_Windows_Controls="clr-namespace:Leadtools.Windows.Controls;assembly=Leadtools.Windows.Controls"
            >
       <DockPanel>
          <StackPanel DockPanel.Dock="Top">
             <RadioButton Name="rbDesignMode" GroupName="UserMode" Content="Design Mode" IsChecked="True" Checked="CheckedChanged"/>
             <RadioButton Name="rbRunMode" GroupName="UserMode" Content="Run Mode" Checked="CheckedChanged"/>
          </StackPanel>
          <ToolBarTray Name="toolbarTray" DockPanel.Dock="Right" Orientation="Vertical"/>
          <Leadtools_Windows_Controls:BitmapSourceViewer x:Name="imageViewer1" Width="NaN" Height="NaN"/>
       </DockPanel>
    </Window>
    
  7. Switch to Window1 code view (for VB project right-click Window1 in the solution explorer then select View Code and for C# project open Window1.xaml.cs file) and add the following lines at the beginning of the file:

    [Visual Basic]

     
    Imports Leadtools.Windows.Annotations
    
    [C#]
     
    using Leadtools.Windows.Annotations;
    
  8. 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;
    
  9. Add the following function code to class Form1:

    [Visual Basic]

     
    Private Sub WindowLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
       imageViewer1.Source = New BitmapImage(New Uri("C:\Users\Public\Documents\LEADTOOLS Images\eye.gif"))
    
       If (Not imageViewer1.Source Is Nothing) 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()
          toolbarTray.ToolBars.Add(annAutomationManager.ToolBar)
    
          ' setup the automation (will create the container as well)
          Dim automation As AnnAutomation = New AnnAutomation(annAutomationManager, imageViewer1)
    
          ' add an event handler for changes to the current designer
          AddHandler automation.CurrentDesignerChanged, New EventHandler(AddressOf automation_CurrentDesignerChanged)
    
          ' setup this automation as the active one
          automation.Active = True
       End If
    End Sub
    
    Private Sub CheckedChanged(ByVal sender As Object, ByVal e As RoutedEventArgs)
       UserModeChanged(sender)
    End Sub
    
    Private Sub UserModeChanged(ByVal sender As Object)
       If (Not annAutomationManager Is Nothing) Then
          annAutomationManager.UserMode = IIf(sender Is rbDesignMode, AnnUserMode.Design, AnnUserMode.Run)
       End If
    End Sub
    
    ' 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 = e.Object
          MessageBox.Show(String.Format("Button with text = {0} was clicked!", btn.Text))
       End If
    End Sub
    
    [C#]
     
    private void WindowLoaded(object sender, RoutedEventArgs e)
    {
       imageViewer1.Source = new BitmapImage(new Uri(@"C:\Users\Public\Documents\LEADTOOLS Images\eye.gif"));
    
       if(imageViewer1.Source != 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();
          toolbarTray.ToolBars.Add(annAutomationManager.ToolBar);
    
          // setup the automation (will create the container as well)
          AnnAutomation automation = new AnnAutomation(annAutomationManager, imageViewer1);
    
          // 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;
       }
    }
    
    private void CheckedChanged(object sender, RoutedEventArgs e)
    {
       UserModeChanged(sender);
    }
    
    private void UserModeChanged(object sender)
    {
       if(annAutomationManager != null)
          annAutomationManager.UserMode = (sender == rbDesignMode) ? AnnUserMode.Design : AnnUserMode.Run;
    }
    
                   // 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));
      }
                   }
    
  10. 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 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 button annotation to call the program listed in the Hyperlink field.