Leadtools.Annotations Requires Document/Medical product license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
AnnDesigner Class
See Also  Members   Example 
Leadtools.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 
Visual Basic (Usage)Copy Code
Dim instance As AnnDesigner
C# 
public abstract class AnnDesigner 
C++/CLI 
public ref class AnnDesigner abstract 

Example

Visual BasicCopy Code
''' Shows how to use designers to create and select annotation objects
Private Class MyForm1 : Inherits Form
   Private myAnnContainer As AnnContainer
   'AnnAutomationManager manager;
   Private viewer As RasterImageViewer
   Private codecs As RasterCodecs
   Private currentDesigner As AnnDesigner
   Public Sub New(ByVal title As String)
      Text = title
      Size = New Size(500, 200)

      viewer = New RasterImageViewer()
      AddHandler viewer.TransformChanged, AddressOf viewer_TransformChanged
      AddHandler viewer.PostImagePaint, AddressOf viewer_PostImagePaint
      AddHandler viewer.MouseDown, AddressOf viewer_MouseDown
      AddHandler viewer.MouseMove, AddressOf viewer_MouseMove
      AddHandler viewer.MouseUp, AddressOf viewer_MouseUp
      AddHandler viewer.LostFocus, AddressOf viewer_LostFocus

      ' load an image into the viewer
      RasterCodecs.Startup()
      codecs = New RasterCodecs()
      viewer.Image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "image1.cmp") ' fix this path to an existing image file on your system
      RasterCodecs.Shutdown()

      ' create and set up the container
      myAnnContainer = New AnnContainer()
      myAnnContainer.Bounds = New AnnRectangle(0, 0, viewer.ImageSize.Width, viewer.ImageSize.Height)
      myAnnContainer.UnitConverter = New AnnUnitConverter(viewer.ImageDpiX, viewer.ImageDpiY)

      ' Create a panel with three buttons
      Dim panel As Panel = New Panel()
      panel.Dock = DockStyle.Left
      Controls.Add(panel)
      panel.BringToFront()

      ' Create three buttons
      Dim buttonLine As Button = New Button()
      AddHandler buttonLine.Click, AddressOf buttonLine_Click
      buttonLine.Text = "Line"
      buttonLine.Dock = DockStyle.Top
      panel.Controls.Add(buttonLine)
      buttonLine.BringToFront()

      Dim buttonRectangle As Button = New Button()
      AddHandler buttonRectangle.Click, AddressOf buttonRectangle_Click
      buttonRectangle.Text = "Rectangle"
      buttonRectangle.Dock = DockStyle.Bottom
      panel.Controls.Add(buttonRectangle)
      buttonRectangle.BringToFront()

      Dim buttonSelect As Button = New Button()
      AddHandler buttonSelect.Click, AddressOf buttonSelect_Click
      buttonSelect.Text = "Select"
      buttonSelect.Dock = DockStyle.Left
      panel.Controls.Add(buttonSelect)
      buttonSelect.BringToFront()

      ' Add the viewer
      viewer.Dock = DockStyle.Fill
      Controls.Add(viewer)
      viewer.BringToFront()

   End Sub

   Private Sub viewer_TransformChanged(ByVal sender As Object, ByVal e As EventArgs)
      ' set up the container transformation
      If Not viewer.Image Is Nothing AndAlso Not myAnnContainer Is Nothing Then
         myAnnContainer.Transform = viewer.Transform.Clone()
      End If
   End Sub

   Private Sub viewer_PostImagePaint(ByVal sender As Object, ByVal e As PaintEventArgs)
      ' draw the container and its objects on this viewer
      If Not viewer.Image Is Nothing AndAlso Not myAnnContainer Is Nothing Then
         myAnnContainer.Draw(e.Graphics)
      End If
   End Sub

   Private Sub buttonSelect_Click(ByVal sender As Object, ByVal e As System.EventArgs)
      ' 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 System.EventArgs)
      ' Line button is clicked

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

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

      ' set up the object template (a 2 pixels-wide pen)
      Dim lineObject As AnnLineObject = New AnnLineObject()
      lineObject.Pen = New AnnPen(Color.Red, New AnnLength(2, AnnUnit.Pixel))
      lineDrawDesigner.ObjectTemplate = lineObject

      StartDrawDesigner(lineDrawDesigner)
   End Sub


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

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

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

      ' set up the object template (a 2 pixels-wide pen)
      Dim rectangleObject As AnnRectangleObject = New AnnRectangleObject()
      rectangleObject.Pen = New AnnPen(Color.Red, New AnnLength(2, AnnUnit.Pixel))
      rectangleObject.Brush = New AnnSolidBrush(Color.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()
         ElseIf 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.Owner = viewer
      drawDesigner.ClipCursor = True
      drawDesigner.Container = myAnnContainer
      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}, EndPoint: {1}", lineObject.StartPoint, lineObject.EndPoint)
      ElseIf TypeOf e.Object Is AnnRectangleObject Then
         Dim rectangleObject As AnnRectangleObject = CType(IIf(TypeOf e.Object Is AnnRectangleObject, e.Object, Nothing), AnnRectangleObject)
         Console.WriteLine("Bounds: {0}", rectangleObject.Bounds)
      End If
   End Sub

   Private Sub viewer_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
      Dim handled As Boolean = False

      ' see if a designer is currently running, if so, let it handle this event
      If Not currentDesigner Is Nothing Then
         handled = currentDesigner.MouseDown(e)
      End If

      If (Not 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 AnnPoint = New AnnPoint(e.X, e.Y)
         Dim obj As AnnObject = myAnnContainer.HitTest(pt, 2)
         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()
               StartEditing(lineEditDesigner, obj, pt)
               lineEditDesigner.MouseDown(e)
            ElseIf TypeOf obj Is AnnRectangleObject Then
               Dim rectangleEditDesigner As AnnRectangleEditDesigner = New AnnRectangleEditDesigner()
               StartEditing(rectangleEditDesigner, obj, pt)
               rectangleEditDesigner.MouseDown(e)
            End If
         End If
      End If
   End Sub

   Private Sub StartEditing(ByVal editDesigner As AnnEditDesigner, ByVal obj As AnnObject, ByVal pt As AnnPoint)
      ' first end any running designers
      EndDesigner()

      ' set up the current designer
      AddHandler editDesigner.Edit, AddressOf OnDesignerEdit
      editDesigner.Owner = viewer
      editDesigner.Container = myAnnContainer
      editDesigner.ClipCursor = True
      editDesigner.EditObject = obj
      editDesigner.HitTestBuffer = 2
      editDesigner.ControlPointsHitTestBuffer = 2
      editDesigner.RotateModifierKey = Keys.Shift
      editDesigner.HitTestObject = obj.HitTest(pt, 2)

      ' set up the edit designer control points
      Dim rectangleControlPoint As AnnRectangleControlPoint = New AnnRectangleControlPoint()
      rectangleControlPoint.Size = New AnnSize(10, 10, AnnUnit.Pixel)
      rectangleControlPoint.Pen = New AnnPen(Color.Blue, New AnnLength(1, AnnUnit.Pixel))
      rectangleControlPoint.Brush = New AnnSolidBrush(Color.White)

      Dim i As Integer = 0
      Do While i < editDesigner.ControlPointCount
         editDesigner.ControlPoints(i) = rectangleControlPoint
         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)
      Else
         Console.WriteLine("HitTestObject: {0}", e.HitTestObject)
      End If
   End Sub

   Private Sub viewer_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
      Dim handled As Boolean = False

      ' see if a designer is currently running, if so, let it handle this event
      If Not currentDesigner Is Nothing Then
         handled = currentDesigner.MouseMove(e)
      End If
   End Sub

   Private Sub viewer_MouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
      Dim handled As Boolean = False

      ' see if a designer is currently running, if so, let it handle this event
      If Not currentDesigner Is Nothing Then
         handled = currentDesigner.MouseUp(e)
      End If
   End Sub

   Private Sub viewer_LostFocus(ByVal sender As Object, ByVal e As EventArgs)
      ' see if a designer is currently running, if so, cancel it
      If Not currentDesigner Is Nothing Then
         currentDesigner.Cancel()
      End If
   End Sub

End Class

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

   AnnContainer container; 
   //AnnAutomationManager manager; 
   RasterImageViewer viewer; 
   RasterCodecs codecs; 
   AnnDesigner currentDesigner; 
   public MyForm1(string title) 
   { 
      Text = title; 
      Size = new Size(500, 200); 
 
      viewer = new RasterImageViewer(); 
      viewer.TransformChanged += new EventHandler(viewer_TransformChanged); 
      viewer.PostImagePaint += new PaintEventHandler(viewer_PostImagePaint); 
      viewer.MouseDown += new MouseEventHandler(viewer_MouseDown); 
      viewer.MouseMove += new MouseEventHandler(viewer_MouseMove); 
      viewer.MouseUp += new MouseEventHandler(viewer_MouseUp); 
      viewer.LostFocus += new EventHandler(viewer_LostFocus); 
 
      // load an image into the viewer 
      RasterCodecs.Startup(); 
      codecs = new RasterCodecs(); 
      string fileName = LeadtoolsExamples.Common.ImagesPath.Path + "image1.cmp"; 
      viewer.Image = codecs.Load(fileName); 
      RasterCodecs.Shutdown(); 
 
      // create and set up the container 
      container = new AnnContainer(); 
      container.Bounds = new AnnRectangle(0, 0, viewer.ImageSize.Width, viewer.ImageSize.Height); 
      container.UnitConverter = new AnnUnitConverter(viewer.ImageDpiX, viewer.ImageDpiY); 
 
      // Create a panel with three buttons 
      Panel panel = new Panel(); 
      panel.Dock = DockStyle.Left; 
      Controls.Add(panel); 
      panel.BringToFront(); 
 
      // Create three buttons 
      Button buttonLine = new Button(); 
      buttonLine.Click +=new EventHandler(buttonLine_Click); 
      buttonLine.Text = "Line"; 
      buttonLine.Dock = DockStyle.Top; 
      panel.Controls.Add(buttonLine); 
      buttonLine.BringToFront(); 
 
      Button buttonRectangle = new Button(); 
      buttonRectangle.Click +=new EventHandler(buttonRectangle_Click); 
      buttonRectangle.Text = "Rectangle"; 
      buttonRectangle.Dock = DockStyle.Bottom; 
      panel.Controls.Add(buttonRectangle); 
      buttonRectangle.BringToFront(); 
 
      Button buttonSelect = new Button(); 
      buttonSelect.Click += new EventHandler(buttonSelect_Click); 
      buttonSelect.Text = "Select"; 
      buttonSelect.Dock = DockStyle.Left; 
      panel.Controls.Add(buttonSelect); 
      buttonSelect.BringToFront(); 
 
      // Add the viewer 
      viewer.Dock = DockStyle.Fill; 
      Controls.Add(viewer); 
      viewer.BringToFront(); 
 
   } 
 
   private void viewer_TransformChanged(object sender, EventArgs e) 
   { 
      // set up the container transformation 
      if(viewer.Image != null && container != null) 
         container.Transform = viewer.Transform.Clone(); 
   } 
 
   private void viewer_PostImagePaint(object sender, PaintEventArgs e) 
   { 
      // draw the container and its objects on this viewer 
      if(viewer.Image != null && container != null) 
         container.Draw(e.Graphics); 
   } 
 
   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, System.EventArgs e) 
   { 
      // Line button is clicked 
 
      // first end any current designer (if any) 
      EndDesigner(); 
 
      // start a new Line draw designer 
      AnnLineDrawDesigner lineDrawDesigner = new AnnLineDrawDesigner(); 
 
      // set up the object template (a 2 pixels-wide pen) 
      AnnLineObject lineObject = new AnnLineObject(); 
      lineObject.Pen = new AnnPen(Color.Red, new AnnLength(2, AnnUnit.Pixel)); 
      lineDrawDesigner.ObjectTemplate = lineObject; 
 
      StartDrawDesigner(lineDrawDesigner); 
   } 
 
 
    private void buttonRectangle_Click(object sender, System.EventArgs e) 
    { 
       // Rectangle button is clicked 
 
       // first end any current designer (if any) 
       EndDesigner(); 
 
       // start a new Rectangle draw designer 
       AnnRectangleDrawDesigner rectangleDrawDesigner = new AnnRectangleDrawDesigner(); 
 
       // set up the object template (a 2 pixels-wide pen) 
       AnnRectangleObject rectangleObject = new AnnRectangleObject(); 
       rectangleObject.Pen = new AnnPen(Color.Red, new AnnLength(2, AnnUnit.Pixel)); 
       rectangleObject.Brush = new AnnSolidBrush(Color.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.Owner = viewer; 
       drawDesigner.ClipCursor = true; 
       drawDesigner.Container = container; 
       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}, EndPoint: {1}", lineObject.StartPoint, lineObject.EndPoint); 
       } 
       else if(e.Object is AnnRectangleObject) 
       { 
          AnnRectangleObject rectangleObject = e.Object as AnnRectangleObject; 
          Console.WriteLine("Bounds: {0}", rectangleObject.Bounds); 
       } 
    } 
 
    private void viewer_MouseDown(object sender, MouseEventArgs e) 
    { 
       bool handled = false; 
 
       // see if a designer is currently running, if so, let it handle this event 
       if(currentDesigner != null) 
          handled = currentDesigner.MouseDown(e); 
 
       if(!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 
          AnnPoint pt = new AnnPoint(e.X, e.Y); 
          AnnObject obj = container.HitTest(pt, 2); 
          if(obj != null) 
          { 
             // yes, start the edit designer for this object 
             if(obj is AnnLineObject) 
             { 
                AnnLineEditDesigner lineEditDesigner = new AnnLineEditDesigner(); 
                StartEditing(lineEditDesigner, obj, pt); 
                lineEditDesigner.MouseDown(e); 
             } 
             else if(obj is AnnRectangleObject) 
             { 
                AnnRectangleEditDesigner rectangleEditDesigner = new AnnRectangleEditDesigner(); 
                StartEditing(rectangleEditDesigner, obj, pt); 
                rectangleEditDesigner.MouseDown(e); 
             } 
          } 
       } 
    } 
 
    private void StartEditing(AnnEditDesigner editDesigner, AnnObject obj, AnnPoint pt) 
    { 
       // first end any running designers 
       EndDesigner(); 
 
       // set up the current designer 
       editDesigner.Edit += new EventHandler<AnnEditDesignerEventArgs>(OnDesignerEdit); 
       editDesigner.Owner = viewer; 
       editDesigner.Container = container; 
       editDesigner.ClipCursor = true; 
       editDesigner.EditObject = obj; 
       editDesigner.HitTestBuffer = 2; 
       editDesigner.ControlPointsHitTestBuffer = 2; 
       editDesigner.RotateModifierKey = Keys.Shift; 
       editDesigner.HitTestObject = obj.HitTest(pt, 2); 
 
       // set up the edit designer control points 
       AnnRectangleControlPoint rectangleControlPoint = new AnnRectangleControlPoint(); 
       rectangleControlPoint.Size = new AnnSize(10, 10, AnnUnit.Pixel); 
       rectangleControlPoint.Pen = new AnnPen(Color.Blue, new AnnLength(1, AnnUnit.Pixel)); 
       rectangleControlPoint.Brush = new AnnSolidBrush(Color.White); 
 
       for(int i = 0; i < editDesigner.ControlPointCount; i++) 
          editDesigner.ControlPoints[i] = rectangleControlPoint; 
 
       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); 
       else 
          Console.WriteLine("HitTestObject: {0}", e.HitTestObject); 
    } 
 
    private void viewer_MouseMove(object sender, MouseEventArgs e) 
    { 
       bool handled = false; 
 
       // see if a designer is currently running, if so, let it handle this event 
       if(currentDesigner != null) 
          handled = currentDesigner.MouseMove(e); 
    } 
 
    private void viewer_MouseUp(object sender, MouseEventArgs e) 
    { 
       bool handled = false; 
 
       // see if a designer is currently running, if so, let it handle this event 
       if(currentDesigner != null) 
          handled = currentDesigner.MouseUp(e); 
    } 
 
    private void viewer_LostFocus(object sender, EventArgs e) 
    { 
       // see if a designer is currently running, if so, cancel it 
       if(currentDesigner != null) 
          currentDesigner.Cancel(); 
    } 
 

 
public void AnnDesigner_AnnDesigner(string title) 

   MyForm1 form = new MyForm1(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 assign an AnnContainer object to the AnnDesigner.Container member and a RasterImageViewer object to the Owner member of a designer. 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 AnnObject.

Inheritance Hierarchy

Requirements

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

See Also

Leadtools.Annotations requires a Document or Medical toolkit license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features