LEADTOOLS Annotations (Leadtools.Annotations assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
AnnRunDesigner Class
See Also  Members  
Leadtools.Annotations Namespace : AnnRunDesigner Class



The AnnRunDesigner Class is available in LEADTOOLS Document and Medical Imaging toolkits.

This class extends AnnDesigner to provide standard functionality for running Annotation objects on an annotation container.

Object Model

AnnRunDesigner ClassIAnnAutomationControl InterfaceAnnContainer ClassAnnObject Class

Syntax

Visual Basic (Declaration) 
<SerializableAttribute()>
Public Class AnnRunDesigner 
   Inherits AnnDesigner
Visual Basic (Usage)Copy Code
Dim instance As AnnRunDesigner
C# 
[SerializableAttribute()]
public class AnnRunDesigner : AnnDesigner 
C++/CLI 
[SerializableAttribute()]
public ref class AnnRunDesigner : public AnnDesigner 

Example

Uses an AnnRunDesigner to handle a button click

Visual BasicCopy Code
Private Class MyForm1 : Inherits Form
      Private myAnnContainer As AnnContainer
      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
         codecs = New RasterCodecs()
         viewer.Image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "image1.cmp")) ' fix this path to an existing image file on your system

         ' 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)

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

         ' add a few objects to the container
         Dim rectObj As AnnRectangleObject = New AnnRectangleObject()
         rectObj.Bounds = New AnnRectangle(100, 100, 200, 200, AnnUnit.Pixel)
         rectObj.Pen = New AnnPen(Color.Blue, New AnnLength(2, AnnUnit.Pixel))
         rectObj.Brush = New AnnSolidBrush(Color.Yellow)
         myAnnContainer.Objects.Add(rectObj)

         Dim buttonObj As AnnButtonObject = New AnnButtonObject()
         buttonObj.Bounds = New AnnRectangle(100, 320, 200, 24, AnnUnit.Pixel)
         buttonObj.Text = "Goto Leadtools website"
         buttonObj.TextColor = Color.Black
         buttonObj.Font = New AnnFont("Arial", New AnnLength(8, AnnUnit.Point), FontStyle.Regular)
         buttonObj.Hyperlink = "http://www.leadtools.com"
         myAnnContainer.Objects.Add(buttonObj)
      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 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 not handled by a designer
            ' check if the click was on top of an existing object that we can start running
            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 run designer for this object
               If TypeOf obj Is AnnButtonObject Then
                  Dim buttonRunDesigner As AnnButtonRunDesigner = New AnnButtonRunDesigner()
                  StartRunning(buttonRunDesigner, obj, e)
               Else
                  Dim runDesigner As AnnRunDesigner = New AnnRunDesigner()
                  StartRunning(runDesigner, obj, e)
               End If
            End If
         End If
      End Sub

      Private Sub StartRunning(ByVal runDesigner As AnnRunDesigner, ByVal obj As AnnObject, ByVal e As MouseEventArgs)
         ' set up the current designer
         AddHandler runDesigner.Run, AddressOf OnDesignerRun
         runDesigner.Owner = viewer
         runDesigner.Container = myAnnContainer
         runDesigner.ClipCursor = True
         runDesigner.Object = obj
         runDesigner.HitTestBuffer = 2
         runDesigner.Start()
         currentDesigner = runDesigner
         currentDesigner.MouseDown(e)
      End Sub

      Private Sub OnDesignerRun(ByVal sender As Object, ByVal e As AnnRunDesignerEventArgs)
         ' show information on the current edit operation
         Console.WriteLine("Object: {0}, Status: {1}, ", e.Object.GetType().Name, e.OperationStatus)

         If e.OperationStatus = AnnDesignerOperationStatus.End Then
            ' check if the object does not have a hyperlink, if so, show a message box
            If e.Object.Hyperlink Is Nothing OrElse e.Object.Hyperlink = String.Empty Then
               MessageBox.Show(String.Format("You clicked an object of type {0} that does not have a hyperlink", e.Object.GetType().Name))
            End If
         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 AnnRunDesigner_AnnRunDesigner(ByVal title As String)
      Dim form As MyForm1 = New MyForm1(title)
      form.ShowDialog()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
class MyForm1 : Form
   {
      AnnContainer container;
      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
         codecs = new RasterCodecs();
         string fileName = Path.Combine(LEAD_VARS.ImagesDir, "image1.cmp");
         viewer.Image = codecs.Load(fileName);

         // 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);

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

         // add a few objects to the container
         AnnRectangleObject rectObj = new AnnRectangleObject();
         rectObj.Bounds = new AnnRectangle(100, 100, 200, 200, AnnUnit.Pixel);
         rectObj.Pen = new AnnPen(Color.Blue, new AnnLength(2, AnnUnit.Pixel));
         rectObj.Brush = new AnnSolidBrush(Color.Yellow);
         container.Objects.Add(rectObj);

         AnnButtonObject buttonObj = new AnnButtonObject();
         buttonObj.Bounds = new AnnRectangle(100, 320, 200, 24, AnnUnit.Pixel);
         buttonObj.Text = "Goto Leadtools website";
         buttonObj.TextColor = Color.Black;
         buttonObj.Font = new AnnFont("Arial", new AnnLength(8, AnnUnit.Point), FontStyle.Regular);
         buttonObj.Hyperlink = @"http://www.leadtools.com";
         container.Objects.Add(buttonObj);
      }

      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 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 not handled by a designer
            // check if the click was on top of an existing object that we can start running
            AnnPoint pt = new AnnPoint(e.X, e.Y);
            AnnObject obj = container.HitTest(pt, 2);
            if(obj != null)
            {
               // yes, start the run designer for this object
               if(obj is AnnButtonObject)
               {
                  AnnButtonRunDesigner buttonRunDesigner = new AnnButtonRunDesigner();
                  StartRunning(buttonRunDesigner, obj, e);
               }
               else
               {
                  AnnRunDesigner runDesigner = new AnnRunDesigner();
                  StartRunning(runDesigner, obj, e);
               }
            }
         }
      }

      private void StartRunning(AnnRunDesigner runDesigner, AnnObject obj, MouseEventArgs e)
      {
         // set up the current designer
         runDesigner.Run += new EventHandler<AnnRunDesignerEventArgs>(OnDesignerRun);
         runDesigner.Owner = viewer;
         runDesigner.Container = container;
         runDesigner.ClipCursor = true;
         runDesigner.Object = obj;
         runDesigner.HitTestBuffer = 2;
         runDesigner.Start();
         currentDesigner = runDesigner;
         currentDesigner.MouseDown(e);
      }

      private void OnDesignerRun(object sender, AnnRunDesignerEventArgs e)
      {
         // show information on the current edit operation
         Console.WriteLine("Object: {0}, Status: {1}, ", e.Object.GetType().Name, e.OperationStatus);

         if(e.OperationStatus == AnnDesignerOperationStatus.End)
         {
            // check if the object does not have a hyperlink, if so, show a message box
            if(e.Object.Hyperlink == null || e.Object.Hyperlink == string.Empty)
               MessageBox.Show(String.Format("You clicked an object of type {0} that does not have a hyperlink", e.Object.GetType().Name));
         }
      }

      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 AnnRunDesigner_AnnRunDesigner(string title)
   {
      MyForm1 form = new MyForm1(title);
      form.ShowDialog();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}

Remarks

Other specific annotation object classes such as AnnButtonRunDesigner and AnnAudioRunDesigner derive from this base class.

Inheritance Hierarchy

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

See Also

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