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



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

Object Model



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 BitmapSourceViewer
  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 BitmapSourceViewer()
           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 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.Left = 100
    rectObj.Top = 100
    rectObj.Width = 200
    rectObj.Height = 200
    rectObj.Stroke = Brushes.Blue
    rectObj.StrokeThickness = 2.0
    rectObj.Fill = Brushes.Yellow
    container.Children.Add(rectObj)

    Dim buttonObj As AnnButtonObject = New AnnButtonObject()
    buttonObj.Left = 100
    buttonObj.Top = 320
    buttonObj.Width = 200
    buttonObj.Height = 2400
    buttonObj.Text = "Goto Leadtools website"
    buttonObj.TextBrush = Brushes.Black
    buttonObj.FontFamily = New FontFamily("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)
       e.RoutedEvent = AnnDesigner.MouseLeftButtonDownEvent

       currentDesigner.RaiseEvent(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 AnnObjectBase = 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)
       e.RoutedEvent = AnnDesigner.MouseMoveEvent

       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

  Private Sub StartRunning(ByVal runDesigner As AnnRunDesigner, ByVal obj As AnnObjectBase, ByVal e As MouseButtonEventArgs)
    ' set up the current designer
       AddHandler runDesigner.Run, AddressOf OnDesignerRun
    runDesigner.IsClipCursor = True
    runDesigner.Object = obj
    runDesigner.Start()
    currentDesigner = runDesigner
    e = New MouseButtonEventArgs(InputManager.Current.PrimaryMouseDevice, e.Timestamp, MouseButton.Left)
    e.RoutedEvent = AnnDesigner.MouseLeftButtonDownEvent
    currentDesigner.RaiseEvent(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
C#Copy Code
class MyWindow1 : Window 

   AnnContainer container; 
   BitmapSourceViewer viewer; 
   AnnDesigner currentDesigner; 
   public MyWindow1(string title) 
   { 
      this.Title = title; 
      this.Width = 500; 
      this.Height = 200; 
 
      // load an image into the viewer 
      viewer = new BitmapSourceViewer(); 
      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 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.Left = 100; 
      rectObj.Top = 100; 
      rectObj.Width = 200; 
      rectObj.Height = 200; 
      rectObj.Stroke = Brushes.Blue; 
      rectObj.StrokeThickness = 2.0; 
      rectObj.Fill = Brushes.Yellow; 
      container.Children.Add(rectObj); 
 
      AnnButtonObject buttonObj = new AnnButtonObject(); 
      buttonObj.Left = 100; 
      buttonObj.Top = 320; 
      buttonObj.Width = 200; 
      buttonObj.Height = 2400; 
      buttonObj.Text = "Goto Leadtools website"; 
      buttonObj.TextBrush = Brushes.Black; 
      buttonObj.FontFamily = new FontFamily("Arial"); 
      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); 
         e.RoutedEvent = AnnDesigner.MouseLeftButtonDownEvent; 
 
         currentDesigner.RaiseEvent(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); 
         AnnObjectBase 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); 
         e.RoutedEvent = AnnDesigner.MouseMoveEvent; 
 
         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); 
      } 
   } 
 
   private void StartRunning(AnnRunDesigner runDesigner, AnnObjectBase obj, MouseButtonEventArgs e) 
   { 
      // set up the current designer 
      runDesigner.Run += new EventHandler<AnnRunDesignerEventArgs>(OnDesignerRun); 
      runDesigner.IsClipCursor = true; 
      runDesigner.Object = obj; 
      runDesigner.Start(); 
      currentDesigner = runDesigner; 
      e = new MouseButtonEventArgs(InputManager.Current.PrimaryMouseDevice, 
         e.Timestamp,  
         MouseButton.Left); 
      e.RoutedEvent = AnnDesigner.MouseLeftButtonDownEvent; 
      currentDesigner.RaiseEvent(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(); 
}

Remarks

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

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.AnnRunDesigner
                           Leadtools.Windows.Annotations.AnnAudioRunDesigner
                           Leadtools.Windows.Annotations.AnnButtonRunDesigner
                           Leadtools.Windows.Annotations.AnnTextRollupRunDesigner

Requirements

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

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.