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



The AnnRunDesigner Class supports WPF/Silverlight.

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. Supported in Silverlight, Windows Phone 7

Object Model

AnnRunDesigner ClassAnnContainer ClassAnnObject Class

Syntax

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

Example

Uses an AnnRunDesigner to handle a button click

Visual BasicCopy Code
Private Class MyWindow1 : Inherits Window
      Private container As AnnContainer
      Private viewer As ImageViewer
      Private currentDesigner As AnnDesigner
      Public Sub New(ByVal title As String)
         Me.Title = title
         Me.Width = 500
         Me.Height = 200

         ' load an image into the viewer
         viewer = New ImageViewer()
         viewer.Source = New BitmapImage(New Uri(Path.Combine(LEAD_VARS.ImagesDir, "cannon.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 dockPanel to contain the controls
         Dim panel As DockPanel = New DockPanel()
         panel.Children.Add(viewer)

         ' set the viewer as a content of the window
         Me.Content = panel

         ' add a few objects to the container
         Dim rectObj As AnnRectangleObject = New AnnRectangleObject()
         rectObj.Rect = New Rect(100, 100, 200, 200)
         rectObj.Stroke = Colors.Blue
         rectObj.StrokeThickness = 2.0
         rectObj.Fill = Colors.Yellow
         container.Children.Add(rectObj)

         Dim buttonObj As AnnButtonObject = New AnnButtonObject()
         buttonObj.Rect = New Rect(100, 320, 200, 2400)
         buttonObj.Text = "Goto Leadtools website"
         buttonObj.Foreground = Colors.Black
         buttonObj.FontFamilyName = "Arial"
         buttonObj.FontSize = 8
         buttonObj.Hyperlink = "http://www.leadtools.com"
         container.Children.Add(buttonObj)
      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)
            currentDesigner.OnMouseRightButtonDown(DirectCast(sender, AnnContainer), e)
         End If

         If (Not e.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 System.Windows.Point = e.GetPosition(Me.container)
            Dim obj As AnnObject = container.HitTest(pt)
            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(Me.container)
                  StartRunning(buttonRunDesigner, obj, e)
               Else
                  Dim runDesigner As AnnRunDesigner = New AnnRunDesigner(Me.container)
                  StartRunning(runDesigner, obj, e)
               End If
            End If
         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.OnMouseMove(DirectCast(sender, AnnContainer), 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)
            currentDesigner.OnMouseLeftButtonUp(DirectCast(sender, AnnContainer), e)
         End If
      End Sub

      Private Sub StartRunning(ByVal runDesigner As AnnRunDesigner, ByVal obj As AnnObject, ByVal e As MouseButtonEventArgs)
         ' set up the current designer
         AddHandler runDesigner.Run, AddressOf OnDesignerRun
         runDesigner.Object = obj
         runDesigner.Start()
         currentDesigner = runDesigner
         e = New MouseButtonEventArgs(InputManager.Current.PrimaryMouseDevice, e.Timestamp, MouseButton.Left)
         currentDesigner.OnMouseLeftButtonUp(runDesigner.Container, 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
   End Class

   Public Sub AnnRunDesigner_AnnRunDesigner(ByVal title As String)
      Dim window As MyWindow1 = New MyWindow1(title)
      window.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 MyWindow1 : Window
   {
      AnnContainer container;
      ImageViewer viewer;
      AnnDesigner currentDesigner;
      public MyWindow1(string title)
      {
         this.Title = title;
         this.Width = 500;
         this.Height = 200;

         // load an image into the viewer
         viewer = new ImageViewer();
         viewer.Source = new BitmapImage(new Uri(Path.Combine(LEAD_VARS.ImagesDir, "cannon.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 dockPanel to contain the controls
         DockPanel panel = new DockPanel();
         panel.Children.Add(viewer);

         // set the viewer as a content of the window
         this.Content = panel;

         // add a few objects to the container
         AnnRectangleObject rectObj = new AnnRectangleObject();
         rectObj.Rect = new Rect(100, 100, 200, 200);
         rectObj.Stroke = Colors.Blue;
         rectObj.Fill = Colors.Yellow;
         rectObj.StrokeThickness = 2.0;
         container.Children.Add(rectObj);

         AnnButtonObject buttonObj = new AnnButtonObject();

         buttonObj.Rect = new Rect(100, 320, 200, 2400);
         buttonObj.Foreground = Colors.Black;
         buttonObj.FontFamilyName = "Arial";
         buttonObj.Text = "Goto Leadtools website";
         buttonObj.FontSize = 8;
         buttonObj.Hyperlink = @"http://www.leadtools.com";
         container.Children.Add(buttonObj);
      }

      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);
            currentDesigner.OnMouseRightButtonDown(sender as AnnContainer, e);
         }

         if(!e.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
            Point pt = e.GetPosition(this.container);
            AnnObject obj = container.HitTest(pt);
            if (obj != null)
            {
               // yes, start the run designer for this object
               if(obj is AnnButtonObject)
               {
                  AnnButtonRunDesigner buttonRunDesigner = new AnnButtonRunDesigner(this.container);
                  StartRunning(buttonRunDesigner, obj, e);
               }
               else
               {
                  AnnRunDesigner runDesigner = new AnnRunDesigner(this.container);
                  StartRunning(runDesigner, obj, e);
               }
            }
         }
      }

      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.OnMouseMove(sender as AnnContainer,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);
            currentDesigner.OnMouseLeftButtonUp(sender as AnnContainer, e);
         }
      }

      private void StartRunning(AnnRunDesigner runDesigner, AnnObject obj, MouseButtonEventArgs e)
      {
         // set up the current designer
         runDesigner.Run += new EventHandler<AnnRunDesignerEventArgs>(OnDesignerRun);
         runDesigner.Object = obj;
         runDesigner.Start();
         currentDesigner = runDesigner;
         e = new MouseButtonEventArgs(InputManager.Current.PrimaryMouseDevice,
            e.Timestamp, 
            MouseButton.Left);
         currentDesigner.OnMouseLeftButtonUp(runDesigner.Container, 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));
         }
      }
   }

   public void AnnRunDesigner_AnnRunDesigner(string title)
   {
      MyWindow1 window = new MyWindow1(title);
      window.ShowDialog();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
SilverlightCSharpCopy Code
class MyWindow1 : ChildWindow 
{
   AnnContainer container;
   ImageViewer viewer;
   AnnDesigner currentDesigner;
   public MyWindow1(string title)
   {
      this.Title = title;
      this.Width = 500;
      this.Height = 200;

      // load an image into the viewer
      viewer = new ImageViewer();
      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();
      BitmapSource bmp = (BitmapSource)viewer.Source;
      container.Width = bmp.PixelWidth;
      container.Height = bmp.PixelHeight;

      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 to contain the controls
      StackPanel panel = new StackPanel();
      panel.Children.Add(viewer);

      // set the viewer as a content of the window
      this.Content = panel;

      // add a few objects to the container
      AnnRectangleObject rectObj = new AnnRectangleObject();
      rectObj.Rect = new Rect(100, 100, 200, 200);
      rectObj.Stroke = Colors.Blue;
      rectObj.Fill = Colors.Yellow;
      rectObj.StrokeThickness = 2.0;
      container.Children.Add(rectObj);
   }

   void container_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
   {
      // see if a designer is currently running, if so, let it handle this event
      if(currentDesigner != null)
      {
         currentDesigner.OnMouseRightButtonDown(sender as AnnContainer, e);
      }

      if(!e.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
         Point pt = e.GetPosition(this.container);
         AnnObject obj = container.HitTest(pt);
         if (obj != null)
         {
            // yes, start the run designer for this object
            AnnRunDesigner runDesigner = new AnnRunDesigner(this.container);
            StartRunning(runDesigner, obj, e);
         }
      }
   }

   void container_MouseMove(object sender, MouseEventArgs e)
   {
      // see if a designer is currently running, if so, let it handle this event
      if(currentDesigner != null)
      {
         currentDesigner.OnMouseMove(sender as AnnContainer,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)
      {
         currentDesigner.OnMouseLeftButtonUp(sender as AnnContainer, e);
      }
   }

   private void StartRunning(AnnRunDesigner runDesigner, AnnObject obj, MouseButtonEventArgs e)
   {
      // set up the current designer
      runDesigner.Run += new EventHandler<AnnRunDesignerEventArgs>(OnDesignerRun);
      runDesigner.Object = obj;
      runDesigner.Start();
      currentDesigner = runDesigner;
      currentDesigner.OnMouseLeftButtonUp(runDesigner.Container, 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));
      }
   }
}

public void AnnRunDesigner_AnnRunDesigner(string title)
{
   MyWindow1 window = new MyWindow1(title);
   window.Show();
}
SilverlightVBCopy Code
Private Class MyWindow1 : Inherits ChildWindow
   Private container As AnnContainer
   Private viewer As ImageViewer
   Private currentDesigner As AnnDesigner
   Public Sub New(ByVal title As String)
      Me.Title = title
      Me.Width = 500
      Me.Height = 200

      ' load an image into the viewer
      viewer = New ImageViewer()
      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()
      Dim bmp As BitmapSource = CType(viewer.Source, BitmapSource)
      container.Width = bmp.PixelWidth
      container.Height = bmp.PixelHeight

      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 to contain the controls
      Dim panel As StackPanel = New StackPanel()
      panel.Children.Add(viewer)

      ' set the viewer as a content of the window
      Me.Content = panel

      ' add a few objects to the container
      Dim rectObj As AnnRectangleObject = New AnnRectangleObject()
      rectObj.Rect = New Rect(100, 100, 200, 200)
      rectObj.Stroke = Colors.Blue
      rectObj.Fill = Colors.Yellow
      rectObj.StrokeThickness = 2.0
      container.Children.Add(rectObj)
   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
         currentDesigner.OnMouseRightButtonDown(TryCast(sender, AnnContainer), e)
      End If

      If (Not e.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 Point = e.GetPosition(Me.container)
         Dim obj As AnnObject = container.HitTest(pt)
         If Not obj Is Nothing Then
            ' yes, start the run designer for this object
            Dim runDesigner As AnnRunDesigner = New AnnRunDesigner(Me.container)
            StartRunning(runDesigner, obj, e)
         End If
      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
         currentDesigner.OnMouseMove(TryCast(sender, AnnContainer),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
         currentDesigner.OnMouseLeftButtonUp(TryCast(sender, AnnContainer), e)
      End If
   End Sub

   Private Sub StartRunning(ByVal runDesigner As AnnRunDesigner, ByVal obj As AnnObject, ByVal e As MouseButtonEventArgs)
      ' set up the current designer
      AddHandler runDesigner.Run, AddressOf OnDesignerRun
      runDesigner.Object = obj
      runDesigner.Start()
      currentDesigner = runDesigner
      currentDesigner.OnMouseLeftButtonUp(runDesigner.Container, 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
End Class

Public Sub AnnRunDesigner_AnnRunDesigner(ByVal title As String)
   Dim window As MyWindow1 = New MyWindow1(title)
   window.Show()
End Sub

Remarks

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

Inheritance Hierarchy

Requirements

Target Platforms: Silverlight 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only)

See Also

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