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



The base class for all the designers in the annotation toolkit.

Object Model


Syntax

Visual Basic (Declaration) 
Public MustInherit Class AnnDesigner 
   Inherits Adorner
Visual Basic (Usage)Copy Code
Dim instance As AnnDesigner
C# 
public abstract class AnnDesigner : Adorner 
C++/CLI 
public ref class AnnDesigner abstract : public Adorner 

Example

Visual BasicCopy Code
''' Shows how to use designers to create and select annotation objects
Private Class MyWindow1 : Inherits Window
  Private container As AnnContainer
  'AnnAutomationManager manager;
  Private viewer As BitmapSourceViewer
  Private currentDesigner As AnnDesigner
  Public Sub New(ByVal title As String)
    Me.Title = title
    Me.Width = 500
    Me.Height = 200

    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 container
    container = New AnnContainer()
    container.Width = viewer.Source.Width
    container.Height = viewer.Source.Height

    AddHandler container.MouseLeftButtonDown, AddressOf container_MouseLeftButtonDown
    AddHandler container.MouseMove, AddressOf container_MouseMove
    AddHandler container.MouseLeftButtonUp, AddressOf container_MouseLeftButtonUp

    ' Set the container as a content of viewer
    viewer.Content = container

    ' Create a panel with three buttons
    Dim stackPanel As StackPanel = New StackPanel()
    DockPanel.SetDock(stackPanel, Dock.Top)

    ' Create three buttons
    Dim buttonLine As Button = New Button()
    AddHandler buttonLine.Click, AddressOf buttonLine_Click
    buttonLine.Content = "Line"
    stackPanel.Children.Add(buttonLine)

    Dim buttonRectangle As Button = New Button()
    AddHandler buttonRectangle.Click, AddressOf buttonRectangle_Click
    buttonRectangle.Content = "Rectangle"
    stackPanel.Children.Add(buttonRectangle)

    Dim buttonSelect As Button = New Button()
    AddHandler buttonSelect.Click, AddressOf buttonSelect_Click
    buttonSelect.Content = "Select"
    stackPanel.Children.Add(buttonSelect)

    ' Add the viewer
    Dim panel As DockPanel = New DockPanel()
    panel.Children.Add(viewer)

    ' set panel as content
    Me.Content = panel
  End Sub

    Private Sub buttonSelect_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
       ' Select button is clicked
       ' cancel any draw designer running
       If Not currentDesigner Is Nothing AndAlso TypeOf currentDesigner Is AnnDrawDesigner Then
          Dim drawDesigner As AnnDrawDesigner = CType(IIf(TypeOf currentDesigner Is AnnDrawDesigner, currentDesigner, Nothing), AnnDrawDesigner)
          drawDesigner.Cancel()
          currentDesigner = Nothing
       End If
    End Sub

  Private Sub buttonLine_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    ' Line button is clicked

    ' first end any current designer (if any)
    EndDesigner()

    ' start a new Line draw designer
    Dim lineDrawDesigner As AnnLineDrawDesigner = New AnnLineDrawDesigner(Me.container)

    ' set up the object template (a 2 pixels-wide pen)
    Dim lineObject As AnnLineObject = New AnnLineObject()
    lineObject.Stroke = Brushes.Red
    lineObject.StrokeThickness = 2.0
    lineDrawDesigner.ObjectTemplate = lineObject

    StartDrawDesigner(lineDrawDesigner)
  End Sub


  Private Sub buttonRectangle_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    ' Rectangle button is clicked

    ' first end any current designer (if any)
    EndDesigner()

    ' start a new Rectangle draw designer
    Dim rectangleDrawDesigner As AnnRectangleDrawDesigner = New AnnRectangleDrawDesigner(Me.container)

    ' set up the object template (a 2 pixels-wide pen)
    Dim rectangleObject As AnnRectangleObject = New AnnRectangleObject()
    rectangleObject.Stroke = Brushes.Red
    rectangleObject.StrokeThickness = 2.0
    rectangleObject.Fill = Brushes.Yellow
    rectangleDrawDesigner.ObjectTemplate = rectangleObject

    StartDrawDesigner(rectangleDrawDesigner)
  End Sub

  Private Sub EndDesigner()
    ' ends any running designer
    If Not currentDesigner Is Nothing Then
       If TypeOf currentDesigner Is AnnEditDesigner Then
         Dim editDesigner As AnnEditDesigner = CType(IIf(TypeOf currentDesigner Is AnnEditDesigner, currentDesigner, Nothing), AnnEditDesigner)
         editDesigner.End()
       Else If TypeOf currentDesigner Is AnnDrawDesigner Then
         Dim drawDesigner As AnnDrawDesigner = CType(IIf(TypeOf currentDesigner Is AnnDrawDesigner, currentDesigner, Nothing), AnnDrawDesigner)
         drawDesigner.Cancel()
       End If
    End If
  End Sub

  Private Sub StartDrawDesigner(ByVal drawDesigner As AnnDrawDesigner)
    ' set up the current designer
       AddHandler drawDesigner.Draw, AddressOf OnDesignerDraw
    drawDesigner.IsClipCursor = True
    currentDesigner = drawDesigner
  End Sub

  Private Sub OnDesignerDraw(ByVal sender As Object, ByVal e As AnnDrawDesignerEventArgs)
    ' show information on the current draw operation
    Console.Write("Status: {0}, Object: {1}, Coordinates:", e.OperationStatus, e.Object.GetType().Name)
    If TypeOf e.Object Is AnnLineObject Then
       Dim lineObject As AnnLineObject = CType(IIf(TypeOf e.Object Is AnnLineObject, e.Object, Nothing), AnnLineObject)
       Console.WriteLine("Start Point: {{0},{1}}, EndPoint: {{2},{3}}", lineObject.X1, lineObject.Y1, lineObject.X2, lineObject.Y2)
    Else If TypeOf e.Object Is AnnRectangleObject Then
       Dim rectangleObject As AnnRectangleObject = CType(IIf(TypeOf e.Object Is AnnRectangleObject, e.Object, Nothing), AnnRectangleObject)
       Console.WriteLine("Left: {0}", rectangleObject.Left)
       Console.WriteLine("Top: {0}", rectangleObject.Top)
       Console.WriteLine("Width: {0}", rectangleObject.Width)
       Console.WriteLine("Height: {0}", rectangleObject.Height)
    End If
  End Sub

  Private Sub container_MouseLeftButtonDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
    ' see if a designer is currently running, if so, let it handle this event
    If Not currentDesigner Is Nothing Then
       e = New MouseButtonEventArgs(InputManager.Current.PrimaryMouseDevice, e.Timestamp, MouseButton.Left)
       e.RoutedEvent = AnnDesigner.MouseLeftButtonDownEvent

       currentDesigner.RaiseEvent(e)
    End If

    If (Not e.Handled) Then
       ' the mouse click was ! handled by a designer
       ' check if the click was on top of an existing object that we can start editing
          Dim pt As System.Windows.Point = e.GetPosition(container)
       Dim obj As AnnObjectBase = container.HitTest(pt)
       If Not obj Is Nothing Then
         ' yes, start the edit designer for this object
         If TypeOf obj Is AnnLineObject Then
           Dim lineEditDesigner As AnnLineEditDesigner = New AnnLineEditDesigner(CType(IIf(TypeOf obj Is AnnLineObject, obj, Nothing), AnnLineObject))
           StartEditing(lineEditDesigner, obj, pt)
           lineEditDesigner.RaiseEvent(e)
         Else If TypeOf obj Is AnnRectangleObject Then
           Dim rectangleEditDesigner As AnnRectangleEditDesigner = New AnnRectangleEditDesigner(CType(IIf(TypeOf obj Is AnnRectangleObject, obj, Nothing), AnnRectangleObject))
           StartEditing(rectangleEditDesigner, obj, pt)
           rectangleEditDesigner.RaiseEvent(e)
         End If
       End If
    End If
  End Sub

    Private Sub StartEditing(ByVal editDesigner As AnnEditDesigner, ByVal obj As AnnObjectBase, ByVal pt As System.Windows.Point)
       ' first end any running designers
       EndDesigner()

       ' set up the current designer
       AddHandler editDesigner.Edit, AddressOf OnDesignerEdit
       editDesigner.IsClipCursor = True
       editDesigner.RotateModifierKey = ModifierKeys.Shift

       Dim i As Integer = 0
       Do While i < editDesigner.ControlPointCount
          ' set up the edit designer control points
          Dim cp As System.Windows.Controls.Primitives.Thumb = New System.Windows.Controls.Primitives.Thumb()
          cp.Width = 10
          cp.Height = 10

          cp.BorderBrush = Brushes.Blue
          cp.BorderThickness = New Thickness(1.0)
          cp.Background = Brushes.White
          editDesigner.ControlPoints(i) = cp
          i += 1
       Loop

       editDesigner.Start()
       currentDesigner = editDesigner
    End Sub

  Private Sub OnDesignerEdit(ByVal sender As Object, ByVal e As AnnEditDesignerEventArgs)
    ' show information on the current draw operation
    Console.Write("Object: {0}, Operation: {1}, Status: {2}, ", e.Object.GetType().Name, e.Operation, e.OperationStatus)
    If e.Operation = AnnEditDesignerOperation.MoveControlPoint Then
       Console.WriteLine("Control Point index: {0}", e.MoveControlPointIndex)
    End If
  End Sub

  Private Sub container_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
    ' see if a designer is currently running, if so, let it handle this event
    If Not currentDesigner Is Nothing Then
       e = New MouseEventArgs(InputManager.Current.PrimaryMouseDevice, e.Timestamp)

       currentDesigner.RaiseEvent(e)
    End If
  End Sub

  Private Sub container_MouseLeftButtonUp(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
    ' see if a designer is currently running, if so, let it handle this event
    If Not currentDesigner Is Nothing Then
       e = New MouseButtonEventArgs(InputManager.Current.PrimaryMouseDevice, e.Timestamp, MouseButton.Left)
       e.RoutedEvent = AnnDesigner.MouseLeftButtonUpEvent

       currentDesigner.RaiseEvent(e)
    End If
  End Sub
End Class

Public Sub AnnDesigner_AnnDesigner(ByVal title As String)
  Dim form As MyWindow1 = New MyWindow1(title)
  form.ShowDialog()
End Sub
C#Copy Code
/// Shows how to use designers to create and select annotation objects 
class MyWindow1 : Window 

   AnnContainer container; 
   //AnnAutomationManager manager; 
   BitmapSourceViewer viewer; 
   AnnDesigner currentDesigner; 
   public MyWindow1(string title) 
   { 
      this.Title = title; 
      this.Width = 500; 
      this.Height = 200; 
 
      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 container 
      container = new AnnContainer(); 
      container.Width = viewer.Source.Width; 
      container.Height = viewer.Source.Height; 
 
      container.MouseLeftButtonDown += new MouseButtonEventHandler(container_MouseLeftButtonDown); 
      container.MouseMove += new MouseEventHandler(container_MouseMove); 
      container.MouseLeftButtonUp += new MouseButtonEventHandler(container_MouseLeftButtonUp); 
 
      // Set the container as a content of viewer 
      viewer.Content = container; 
 
      // Create a panel with three buttons 
      StackPanel stackPanel = new StackPanel(); 
      DockPanel.SetDock(stackPanel, Dock.Top); 
 
      // Create three buttons 
      Button buttonLine = new Button(); 
      buttonLine.Click += new RoutedEventHandler(buttonLine_Click); 
      buttonLine.Content = "Line"; 
      stackPanel.Children.Add(buttonLine); 
 
      Button buttonRectangle = new Button(); 
      buttonRectangle.Click += new RoutedEventHandler(buttonRectangle_Click); 
      buttonRectangle.Content = "Rectangle"; 
      stackPanel.Children.Add(buttonRectangle); 
 
      Button buttonSelect = new Button(); 
      buttonSelect.Click += new RoutedEventHandler(buttonSelect_Click); 
      buttonSelect.Content = "Select"; 
      stackPanel.Children.Add(buttonSelect); 
 
      // Add the viewer 
      DockPanel panel = new DockPanel(); 
      panel.Children.Add(viewer); 
 
      // set panel as content 
      this.Content = panel; 
   } 
 
   private void buttonSelect_Click(object sender, System.EventArgs e) 
   { 
      // Select button is clicked 
      // cancel any draw designer running 
      if(currentDesigner != null && currentDesigner is AnnDrawDesigner) 
      { 
         AnnDrawDesigner drawDesigner = currentDesigner as AnnDrawDesigner; 
         drawDesigner.Cancel(); 
         currentDesigner = null; 
      } 
   } 
 
   private void buttonLine_Click(object sender, RoutedEventArgs e) 
   { 
      // Line button is clicked 
 
      // first end any current designer (if any) 
      EndDesigner(); 
 
      // start a new Line draw designer 
      AnnLineDrawDesigner lineDrawDesigner = new AnnLineDrawDesigner(this.container); 
 
      // set up the object template (a 2 pixels-wide pen) 
      AnnLineObject lineObject = new AnnLineObject(); 
      lineObject.Stroke = Brushes.Red; 
      lineObject.StrokeThickness = 2.0; 
      lineDrawDesigner.ObjectTemplate = lineObject; 
 
      StartDrawDesigner(lineDrawDesigner); 
   } 
 
 
   private void buttonRectangle_Click(object sender, RoutedEventArgs e) 
   { 
      // Rectangle button is clicked 
 
      // first end any current designer (if any) 
      EndDesigner(); 
 
      // start a new Rectangle draw designer 
      AnnRectangleDrawDesigner rectangleDrawDesigner = new AnnRectangleDrawDesigner(this.container); 
 
      // set up the object template (a 2 pixels-wide pen) 
      AnnRectangleObject rectangleObject = new AnnRectangleObject(); 
      rectangleObject.Stroke = Brushes.Red; 
      rectangleObject.StrokeThickness = 2.0; 
      rectangleObject.Fill = Brushes.Yellow; 
      rectangleDrawDesigner.ObjectTemplate = rectangleObject; 
 
      StartDrawDesigner(rectangleDrawDesigner); 
   } 
 
   private void EndDesigner() 
   { 
      // ends any running designer 
      if(currentDesigner != null) 
      { 
         if(currentDesigner is AnnEditDesigner) 
         { 
            AnnEditDesigner editDesigner = currentDesigner as AnnEditDesigner; 
            editDesigner.End(); 
         } 
         else if(currentDesigner is AnnDrawDesigner) 
         { 
            AnnDrawDesigner drawDesigner = currentDesigner as AnnDrawDesigner; 
            drawDesigner.Cancel(); 
         } 
      } 
   } 
 
   private void StartDrawDesigner(AnnDrawDesigner drawDesigner) 
   { 
      // set up the current designer 
      drawDesigner.Draw += new EventHandler<AnnDrawDesignerEventArgs>(OnDesignerDraw); 
      drawDesigner.IsClipCursor = true; 
      currentDesigner = drawDesigner; 
   } 
 
   private void OnDesignerDraw(object sender, AnnDrawDesignerEventArgs e) 
   { 
      // show information on the current draw operation 
      Console.Write("Status: {0}, Object: {1}, Coordinates:", e.OperationStatus, e.Object.GetType().Name); 
      if(e.Object is AnnLineObject) 
      { 
         AnnLineObject lineObject = e.Object as AnnLineObject; 
         Console.WriteLine("Start Point: {{0},{1}}, EndPoint: {{2},{3}}", lineObject.X1, lineObject.Y1, lineObject.X2, lineObject.Y2); 
      } 
      else if(e.Object is AnnRectangleObject) 
      { 
         AnnRectangleObject rectangleObject = e.Object as AnnRectangleObject; 
         Console.WriteLine("Left: {0}", rectangleObject.Left); 
         Console.WriteLine("Top: {0}", rectangleObject.Top); 
         Console.WriteLine("Width: {0}", rectangleObject.Width); 
         Console.WriteLine("Height: {0}", rectangleObject.Height); 
      } 
   } 
 
   void container_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
   { 
      // see if a designer is currently running, if so, let it handle this event 
      if(currentDesigner != null) 
      { 
         e = new MouseButtonEventArgs(InputManager.Current.PrimaryMouseDevice, 
            e.Timestamp, 
            MouseButton.Left); 
         e.RoutedEvent = AnnDesigner.MouseLeftButtonDownEvent; 
 
         currentDesigner.RaiseEvent(e); 
      } 
 
      if(!e.Handled) 
      { 
         // the mouse click was ! handled by a designer 
         // check if the click was on top of an existing object that we can start editing 
         Point pt = e.GetPosition(container); 
         AnnObjectBase obj = container.HitTest(pt); 
         if(obj != null) 
         { 
            // yes, start the edit designer for this object 
            if(obj is AnnLineObject) 
            { 
               AnnLineEditDesigner lineEditDesigner = new AnnLineEditDesigner(obj as AnnLineObject); 
               StartEditing(lineEditDesigner, obj, pt); 
               lineEditDesigner.RaiseEvent(e); 
            } 
            else if(obj is AnnRectangleObject) 
            { 
               AnnRectangleEditDesigner rectangleEditDesigner = new AnnRectangleEditDesigner(obj as AnnRectangleObject); 
               StartEditing(rectangleEditDesigner, obj, pt); 
               rectangleEditDesigner.RaiseEvent(e); 
            } 
         } 
      } 
   } 
 
   private void StartEditing(AnnEditDesigner editDesigner, AnnObjectBase obj, Point pt) 
   { 
      // first end any running designers 
      EndDesigner(); 
 
      // set up the current designer 
      editDesigner.Edit += new EventHandler<AnnEditDesignerEventArgs>(OnDesignerEdit); 
      editDesigner.IsClipCursor = true; 
      editDesigner.RotateModifierKey = ModifierKeys.Shift; 
 
      for(int i = 0; i < editDesigner.ControlPointCount; i++) 
      { 
         // set up the edit designer control points 
         System.Windows.Controls.Primitives.Thumb cp = new System.Windows.Controls.Primitives.Thumb(); 
         cp.Width = cp.Height = 10;; 
         cp.BorderBrush = Brushes.Blue; 
         cp.BorderThickness = new Thickness(1.0); 
         cp.Background = Brushes.White; 
         editDesigner.ControlPoints[i] = cp; 
      } 
 
      editDesigner.Start(); 
      currentDesigner = editDesigner; 
   } 
 
   private void OnDesignerEdit(object sender, AnnEditDesignerEventArgs e) 
   { 
      // show information on the current draw operation 
      Console.Write("Object: {0}, Operation: {1}, Status: {2}, ", e.Object.GetType().Name, e.Operation, e.OperationStatus); 
      if(e.Operation == AnnEditDesignerOperation.MoveControlPoint) 
         Console.WriteLine("Control Point index: {0}", e.MoveControlPointIndex); 
   } 
 
   void container_MouseMove(object sender, MouseEventArgs e) 
   { 
      // see if a designer is currently running, if so, let it handle this event 
      if(currentDesigner != null) 
      { 
         e = new MouseEventArgs(InputManager.Current.PrimaryMouseDevice, 
            e.Timestamp); 
 
         currentDesigner.RaiseEvent(e); 
      } 
   } 
 
   void container_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) 
   { 
      // see if a designer is currently running, if so, let it handle this event 
      if(currentDesigner != null) 
      { 
         e = new MouseButtonEventArgs(InputManager.Current.PrimaryMouseDevice, 
            e.Timestamp, 
            MouseButton.Left); 
         e.RoutedEvent = AnnDesigner.MouseLeftButtonUpEvent; 
 
         currentDesigner.RaiseEvent(e); 
      } 
   } 

 
public void AnnDesigner_AnnDesigner(string title) 

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

Remarks

An AnnDesigner derived class controls the user interface functionality involved in drawing, editing or running an object. This class provides the basic functionality common to all the designers such as hooking into a container, clipping the mouse cursor, etc.

You pass an AnnContainer object to this class constructor. Then based on the exact designer functionality, it will hook into the various mouse events to draw a new, edit an existing (by moving, resizing, etc.) or run (if the container is in run user mode) an AnnObjectBase.

Inheritance Hierarchy

System.Object
   System.Windows.Threading.DispatcherObject
      System.Windows.DependencyObject
         System.Windows.Media.Visual
            System.Windows.UIElement
               System.Windows.FrameworkElement
                  System.Windows.Documents.Adorner
                     Leadtools.Windows.Annotations.AnnDesigner
                        Leadtools.Windows.Annotations.AnnDrawDesigner
                        Leadtools.Windows.Annotations.AnnEditDesigner
                        Leadtools.Windows.Annotations.AnnRunDesigner

Requirements

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

See Also

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