Leadtools.Windows.Annotations Requires Document/Medical license. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
AnnAutomationManager Class
See Also  Members   Example 
Leadtools.Windows.Annotations Namespace : AnnAutomationManager Class



Manages the automation mode for an annotatation application.

Syntax

Visual Basic (Declaration) 
Public Class AnnAutomationManager 
Visual Basic (Usage)Copy Code
Dim instance As AnnAutomationManager
C# 
public class AnnAutomationManager 
C++/CLI 
public ref class AnnAutomationManager 

Example

This example creates an automated annotation application. This example will only use the line and rectangle objects. The example lets you select objects from the toolbar, draw objects on top of the image, select objects and move them or change them, right click on any object to show its properties, etc.

Visual BasicCopy Code
Private Class MyWindow1 : Inherits Window
  Private manager As AnnAutomationManager
  Private viewer As BitmapSourceViewer
  Public Sub New(ByVal title As String)
    Me.Title = title
    Me.Width = 400
    Me.Height = 400

    viewer = New BitmapSourceViewer()
    ' load an image into the viewer
           viewer.Source = New BitmapImage(New Uri(LeadtoolsExamples.Common.ImagesPath.Path + "ScarletMacaws.jpg")) ' fix this path to an existing image file on your system
    viewer.Width = Double.NaN
    viewer.Height = Double.NaN
    ' create and set up the automation manager
    manager = New AnnAutomationManager()

    ' Create only the line and rectangle automation objects
    CreateMyAutomationObjects(manager)

    ' You can instruct the manager to create the default (all) automation objects.
    ' comment out the call to CreateMyAutomationObjects and call this instead:
    'theManager.CreateDefaultObjects();

    ' create the toolbar and add it to the ToolBarTray
    manager.CreateToolBar()

    Dim tbt As ToolBarTray = New ToolBarTray()
    tbt.Orientation = Orientation.Horizontal
    DockPanel.SetDock(tbt, Dock.Top)
    tbt.ToolBars.Add(manager.ToolBar)

    Dim dp As DockPanel = New DockPanel()
    dp.Children.Add(tbt)
    dp.Children.Add(viewer)

    ' set the DockPanel as a content of the window.
    Me.Content = dp

    ' set up the automation (will create the container as well)
    Dim automation As AnnAutomation = New AnnAutomation(manager, viewer)

    ' set up this automation as the active one
    automation.Active = True

    automation.UndoCapacity = 12
  End Sub

  Private Sub CreateMyAutomationObjects(ByVal manager As AnnAutomationManager)
    ' set up the select automation object
    Dim selObj As AnnAutomationObject = New AnnAutomationObject()
    selObj.Id = AnnAutomationManager.SelectObjectId
    selObj.Name = "Select"
    selObj.Object = Nothing
    selObj.DrawDesignerType = GetType(AnnRectangleDrawDesigner)
    selObj.EditDesignerType = Nothing
    selObj.RunDesignerType = Nothing

    ' create the toolbar button (or you can load the image from a disk file or resource)
    Dim dv As DrawingVisual = New DrawingVisual()
       Using dc As DrawingContext = dv.RenderOpen()
          dc.DrawRectangle(New SolidColorBrush(Color.FromRgb(236, 233, 216)), Nothing, New Rect(0, 0, 24, 24))
          dc.DrawLine(New Pen(Brushes.Black, 2), New System.Windows.Point(4, 4), New System.Windows.Point(22, 22))
          dc.DrawLine(New Pen(Brushes.Black, 2), New System.Windows.Point(4, 22), New System.Windows.Point(22, 4))

          dc.Close()

          Dim bmp As RenderTargetBitmap = New RenderTargetBitmap(24, 24, 96, 96, PixelFormats.Pbgra32)
          bmp.Render(dv)
          selObj.ToolBarButtonImage = bmp
       End Using

       selObj.ToolBarButtonToolTip = New ToolTip()
       selObj.ToolBarButtonToolTip.Content = "Select"
       selObj.DrawCursor = Cursors.Hand
       selObj.ContextMenu = Nothing

       Dim selectObj As AnnSelectObject = New AnnSelectObject()
       selectObj.BackStroke = Brushes.Black
       selectObj.StrokeDashCap = PenLineCap.Square
       selectObj.StrokeEndLineCap = PenLineCap.Square
       selectObj.StrokeLineJoin = PenLineJoin.Round
       selectObj.StrokeMiterLimit = 10.0
       selectObj.StrokeStartLineCap = PenLineCap.Square

       selectObj.StrokeDashArray.Add(1.5)
       selectObj.StrokeDashArray.Add(1.5)

       selectObj.StrokeDashOffset = 2.0
       selectObj.Stroke = Brushes.White
       selectObj.StrokeThickness = 2.0

       selObj.Object = selectObj

       manager.Objects.Add(selObj)

       ' set up the line automation object
       Dim lineObj As AnnAutomationObject = New AnnAutomationObject()
       lineObj.Id = AnnAutomationManager.LineObjectId
       lineObj.Name = "Line"
       Dim line As AnnLineObject = New AnnLineObject()
       line.Stroke = Brushes.Red
       line.StrokeThickness = 2.0
       lineObj.Object = line
       lineObj.DrawDesignerType = GetType(AnnLineDrawDesigner)
       lineObj.EditDesignerType = GetType(AnnLineEditDesigner)
       lineObj.RunDesignerType = GetType(AnnRunDesigner)

       Using dc As DrawingContext = dv.RenderOpen()
          dc.DrawRectangle(New SolidColorBrush(Color.FromRgb(236, 233, 216)), Nothing, New Rect(0, 0, 24, 24))
          dc.DrawLine(New Pen(Brushes.Black, 2), New System.Windows.Point(4, 4), New System.Windows.Point(22, 22))

          dc.Close()

          Dim bmp As RenderTargetBitmap = New RenderTargetBitmap(24, 24, 96, 96, PixelFormats.Pbgra32)
          bmp.Render(dv)
          lineObj.ToolBarButtonImage = bmp
       End Using

       lineObj.ToolBarButtonToolTip = New ToolTip()
       lineObj.ToolBarButtonToolTip.Content = "Draw new line object"
       lineObj.DrawCursor = Cursors.Cross
       lineObj.ContextMenu = AnnAutomationManager.CreateDefaultObjectContextMenu(lineObj.Id)
       manager.Objects.Add(lineObj)

       ' set up the rectangle automation object
       Dim rectObj As AnnAutomationObject = New AnnAutomationObject()
       rectObj.Id = AnnAutomationManager.RectangleObjectId
       rectObj.Name = "Rectangle"
       Dim rect As AnnRectangleObject = New AnnRectangleObject()
       rect.Stroke = Brushes.Red
       rect.StrokeThickness = 2.0
       rect.Fill = Brushes.White
       rectObj.Object = rect
       rectObj.DrawDesignerType = GetType(AnnRectangleDrawDesigner)
       rectObj.EditDesignerType = GetType(AnnRectangleEditDesigner)
       rectObj.RunDesignerType = GetType(AnnRunDesigner)

       Using dc As DrawingContext = dv.RenderOpen()
          dc.DrawRectangle(New SolidColorBrush(Color.FromRgb(236, 233, 216)), Nothing, New Rect(0, 0, 24, 24))
          dc.DrawRectangle(Nothing, New Pen(Brushes.Black, 2), New Rect(2, 4, 20, 18))

          dc.Close()

          Dim bmp As RenderTargetBitmap = New RenderTargetBitmap(24, 24, 96, 96, PixelFormats.Pbgra32)
          bmp.Render(dv)
          rectObj.ToolBarButtonImage = bmp
       End Using

       rectObj.ToolBarButtonToolTip = New ToolTip()
       rectObj.ToolBarButtonToolTip.Content = "Draw new rectangle object"
       rectObj.DrawCursor = Cursors.Cross
       rectObj.ContextMenu = AnnAutomationManager.CreateDefaultObjectContextMenu(rectObj.Id)
       manager.Objects.Add(rectObj)

       ' set up the group automation object (always needed)
       Dim groupObj As AnnAutomationObject = New AnnAutomationObject()
       groupObj.Id = AnnAutomationManager.GroupObjectId
       groupObj.Name = "Group"
       groupObj.Object = New AnnGroupObject()
       groupObj.DrawDesignerType = Nothing
       groupObj.EditDesignerType = GetType(AnnGroupEditDesigner)
       groupObj.RunDesignerType = GetType(AnnRunDesigner)
       groupObj.ToolBarButtonImage = Nothing ' group is not in the toolbar
       groupObj.ToolBarButtonToolTip = Nothing
       groupObj.DrawCursor = Nothing
       groupObj.ContextMenu = AnnAutomationManager.CreateDefaultObjectContextMenu(groupObj.Id)
       manager.Objects.Add(groupObj)
    End Sub
End Class

Private Sub AnnAutomationManager_AnnAutomationManager(ByVal title As String)
  Dim window As MyWindow1 = New MyWindow1(title)
  window.ShowDialog()
End Sub
C#Copy Code
private class MyWindow1 : Window 

   AnnAutomationManager manager; 
   BitmapSourceViewer viewer; 
   public MyWindow1(string title) 
   { 
      this.Title = title; 
      this.Width = 400; 
      this.Height = 400; 
 
      viewer = new BitmapSourceViewer(); 
      // load an image into the viewer 
      viewer.Source = new BitmapImage(new Uri(LeadtoolsExamples.Common.ImagesPath.Path + "ScarletMacaws.jpg"));  // fix this path to an existing image file on your system 
      viewer.Width = double.NaN; 
      viewer.Height = double.NaN; 
      // create and set up the automation manager 
      manager = new AnnAutomationManager(); 
 
      // Create only the line and rectangle automation objects 
      CreateMyAutomationObjects(manager); 
 
      // You can instruct the manager to create the default (all) automation objects. 
      // comment out the call to CreateMyAutomationObjects and call this instead: 
      //theManager.CreateDefaultObjects(); 
 
      // create the toolbar and add it to the ToolBarTray 
      manager.CreateToolBar(); 
 
      ToolBarTray tbt = new ToolBarTray(); 
      tbt.Orientation = Orientation.Horizontal; 
      DockPanel.SetDock(tbt, Dock.Top); 
      tbt.ToolBars.Add(manager.ToolBar); 
 
      DockPanel dp = new DockPanel(); 
      dp.Children.Add(tbt); 
      dp.Children.Add(viewer); 
 
      // set the DockPanel as a content of the window. 
      this.Content = dp; 
 
      // set up the automation (will create the container as well) 
      AnnAutomation automation = new AnnAutomation(manager, viewer); 
 
      // set up this automation as the active one 
      automation.Active = true; 
 
      automation.UndoCapacity = 12; 
   } 
 
   private void CreateMyAutomationObjects(AnnAutomationManager manager) 
   { 
      // set up the select automation object 
      AnnAutomationObject selObj = new AnnAutomationObject(); 
      selObj.Id = AnnAutomationManager.SelectObjectId; 
      selObj.Name = "Select"; 
      selObj.Object = null; 
      selObj.DrawDesignerType = typeof(AnnRectangleDrawDesigner); 
      selObj.EditDesignerType = null; 
      selObj.RunDesignerType = null; 
 
      // create the toolbar button (or you can load the image from a disk file or resource) 
      DrawingVisual dv = new DrawingVisual(); 
      using(DrawingContext dc = dv.RenderOpen()) 
      { 
         dc.DrawRectangle(new SolidColorBrush(Color.FromRgb(236, 233, 216)), null, new Rect(0, 0, 24, 24)); 
         dc.DrawLine(new Pen(Brushes.Black, 2), new Point(4, 4), new Point(22, 22)); 
         dc.DrawLine(new Pen(Brushes.Black, 2), new Point(4, 22), new Point(22, 4)); 
 
         dc.Close(); 
 
         RenderTargetBitmap bmp = new RenderTargetBitmap(24, 24, 96, 96, PixelFormats.Pbgra32); 
         bmp.Render(dv); 
         selObj.ToolBarButtonImage = bmp; 
      } 
 
      selObj.ToolBarButtonToolTip = new ToolTip(); 
      selObj.ToolBarButtonToolTip.Content = "Select"; 
      selObj.DrawCursor = Cursors.Hand; 
      selObj.ContextMenu = null; 
 
      AnnSelectObject selectObj = new AnnSelectObject(); 
      selectObj.BackStroke = Brushes.Black; 
      selectObj.StrokeDashCap = PenLineCap.Square; 
      selectObj.StrokeEndLineCap = PenLineCap.Square; 
      selectObj.StrokeLineJoin = PenLineJoin.Round; 
      selectObj.StrokeMiterLimit = 10.0; 
      selectObj.StrokeStartLineCap = PenLineCap.Square; 
 
      selectObj.StrokeDashArray.Add(1.5); 
      selectObj.StrokeDashArray.Add(1.5); 
 
      selectObj.StrokeDashOffset = 2.0; 
      selectObj.Stroke = Brushes.White; 
      selectObj.StrokeThickness = 2.0; 
 
      selObj.Object = selectObj; 
 
      manager.Objects.Add(selObj); 
 
      // set up the line automation object 
      AnnAutomationObject lineObj = new AnnAutomationObject(); 
      lineObj.Id = AnnAutomationManager.LineObjectId; 
      lineObj.Name = "Line"; 
      AnnLineObject line = new AnnLineObject(); 
      line.Stroke = Brushes.Red; 
      line.StrokeThickness = 2.0; 
      lineObj.Object = line; 
      lineObj.DrawDesignerType = typeof(AnnLineDrawDesigner); 
      lineObj.EditDesignerType = typeof(AnnLineEditDesigner); 
      lineObj.RunDesignerType = typeof(AnnRunDesigner); 
 
      using(DrawingContext dc = dv.RenderOpen()) 
      { 
         dc.DrawRectangle(new SolidColorBrush(Color.FromRgb(236, 233, 216)), null, new Rect(0, 0, 24, 24)); 
         dc.DrawLine(new Pen(Brushes.Black, 2), new Point(4, 4), new Point(22, 22)); 
 
         dc.Close(); 
 
         RenderTargetBitmap bmp = new RenderTargetBitmap(24, 24, 96, 96, PixelFormats.Pbgra32); 
         bmp.Render(dv); 
         lineObj.ToolBarButtonImage = bmp; 
      } 
 
      lineObj.ToolBarButtonToolTip = new ToolTip(); 
      lineObj.ToolBarButtonToolTip.Content = "Draw new line object"; 
      lineObj.DrawCursor = Cursors.Cross; 
      lineObj.ContextMenu = AnnAutomationManager.CreateDefaultObjectContextMenu(lineObj.Id); 
      manager.Objects.Add(lineObj); 
 
      // set up the rectangle automation object 
      AnnAutomationObject rectObj = new AnnAutomationObject(); 
      rectObj.Id = AnnAutomationManager.RectangleObjectId; 
      rectObj.Name = "Rectangle"; 
      AnnRectangleObject rect = new AnnRectangleObject(); 
      rect.Stroke = Brushes.Red; 
      rect.StrokeThickness = 2.0; 
      rect.Fill = Brushes.White; 
      rectObj.Object = rect; 
      rectObj.DrawDesignerType = typeof(AnnRectangleDrawDesigner); 
      rectObj.EditDesignerType = typeof(AnnRectangleEditDesigner); 
      rectObj.RunDesignerType = typeof(AnnRunDesigner); 
 
      using(DrawingContext dc = dv.RenderOpen()) 
      { 
         dc.DrawRectangle(new SolidColorBrush(Color.FromRgb(236, 233, 216)), null, new Rect(0, 0, 24, 24)); 
         dc.DrawRectangle(null, new Pen(Brushes.Black, 2), new Rect(2, 4, 20, 18)); 
 
         dc.Close(); 
 
         RenderTargetBitmap bmp = new RenderTargetBitmap(24, 24, 96, 96, PixelFormats.Pbgra32); 
         bmp.Render(dv); 
         rectObj.ToolBarButtonImage = bmp; 
      } 
 
      rectObj.ToolBarButtonToolTip = new ToolTip(); 
      rectObj.ToolBarButtonToolTip.Content = "Draw new rectangle object"; 
      rectObj.DrawCursor = Cursors.Cross; 
      rectObj.ContextMenu = AnnAutomationManager.CreateDefaultObjectContextMenu(rectObj.Id); 
      manager.Objects.Add(rectObj); 
 
      // set up the group automation object (always needed) 
      AnnAutomationObject groupObj = new AnnAutomationObject(); 
      groupObj.Id = AnnAutomationManager.GroupObjectId; 
      groupObj.Name = "Group"; 
      groupObj.Object = new AnnGroupObject(); 
      groupObj.DrawDesignerType = null; 
      groupObj.EditDesignerType = typeof(AnnGroupEditDesigner); 
      groupObj.RunDesignerType = typeof(AnnRunDesigner); 
      groupObj.ToolBarButtonImage = null;  // group is not in the toolbar 
      groupObj.ToolBarButtonToolTip = null; 
      groupObj.DrawCursor = null; 
      groupObj.ContextMenu = AnnAutomationManager.CreateDefaultObjectContextMenu(groupObj.Id); 
      manager.Objects.Add(groupObj); 
   } 

 
private void AnnAutomationManager_AnnAutomationManager(string title) 

   MyWindow1 window = new MyWindow1(title); 
   window.ShowDialog(); 
}

Remarks

The AnnAutomationManager class holds the collection of all AnnAutomation objects in the application as well the annotation toolbar. Cursor, keyboard, context sensitive menus, property dialogs and various other user interface options and settings are stored here as well.

An automated annotation application usually creates one AnnAutomationManager object per application.

Inheritance Hierarchy

System.Object
   Leadtools.Windows.Annotations.AnnAutomationManager

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Vista, and Windows Server 2003 family

See Also

AnnAutomationManager requires a Document/Medical product license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features and Unlocking Special LEAD Features.