C#
VB
C++
This class extends AnnDesigner to provide standard functionality for running Annotation objects on an annotation container.
public class AnnRunDesigner : AnnDesigner Public Class AnnRunDesignerInherits Leadtools.Windows.Annotations.AnnDesigner
public ref class AnnRunDesigner : public Leadtools.Windows.Annotations.AnnDesigner Other specific annotation object classes such as AnnButtonRunDesigner derive from this base class.
Uses an AnnRunDesigner to handle a button click
using Leadtools.Windows.Controls;using Leadtools.Windows.Annotations;using Leadtools.Demos;using Leadtools.Help;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 viewerviewer = new ImageViewer();// fix this path to an existing image file on your systemviewer.Source = new BitmapImage(new Uri(Path.Combine(LEAD_VARS.ImagesDir, "cannon.jpg")));viewer.Width = double.NaN;viewer.Height = double.NaN;// create and set up the containercontainer = 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 viewerviewer.Content = container;// Create a dockPanel to contain the controlsDockPanel panel = new DockPanel();panel.Children.Add(viewer);// set the viewer as a content of the windowthis.Content = panel;// add a few objects to the containerAnnRectangleObject 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 = @"https://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 eventif (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 runningPoint pt = e.GetPosition(this.container);AnnObject obj = container.HitTest(pt);if (obj != null){// yes, start the run designer for this objectif (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 eventif (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 eventif (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 designerrunDesigner.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 operationConsole.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 boxif (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";}
Imports Leadtools.Windows.ControlsImports Leadtools.Windows.AnnotationsPrivate Class MyWindow1 : Inherits WindowPrivate container As AnnContainerPrivate viewer As ImageViewerPrivate currentDesigner As AnnDesignerPublic Sub New(ByVal title As String)Me.Title = titleMe.Width = 500Me.Height = 200' load an image into the viewerviewer = New ImageViewer()' fix this path to an existing image file on your systemviewer.Source = New BitmapImage(New Uri(Path.Combine(LEAD_VARS.ImagesDir, "cannon.jpg")))viewer.Width = Double.NaNviewer.Height = Double.NaN' create and set up the containercontainer = New AnnContainer()container.Width = viewer.Source.Widthcontainer.Height = viewer.Source.HeightAddHandler container.MouseLeftButtonDown, AddressOf container_MouseLeftButtonDownAddHandler container.MouseMove, AddressOf container_MouseMoveAddHandler container.MouseLeftButtonUp, AddressOf container_MouseLeftButtonUp' Set the container as a content of viewerviewer.Content = container' Create a dockPanel to contain the controlsDim panel As DockPanel = New DockPanel()panel.Children.Add(viewer)' set the viewer as a content of the windowMe.Content = panel' add a few objects to the containerDim rectObj As AnnRectangleObject = New AnnRectangleObject()rectObj.Rect = New Rect(100, 100, 200, 200)rectObj.Stroke = Colors.BluerectObj.StrokeThickness = 2.0rectObj.Fill = Colors.Yellowcontainer.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.BlackbuttonObj.FontFamilyName = "Arial"buttonObj.FontSize = 8buttonObj.Hyperlink = "https://www.leadtools.com"container.Children.Add(buttonObj)End SubPrivate Sub container_MouseLeftButtonDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)' see if a designer is currently running, if so, let it handle this eventIf Not currentDesigner Is Nothing Thene = New MouseButtonEventArgs(InputManager.Current.PrimaryMouseDevice, e.Timestamp, MouseButton.Left)currentDesigner.OnMouseRightButtonDown(DirectCast(sender, AnnContainer), e)End IfIf (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 runningDim 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 objectIf TypeOf obj Is AnnButtonObject ThenDim buttonRunDesigner As AnnButtonRunDesigner = New AnnButtonRunDesigner(Me.container)StartRunning(buttonRunDesigner, obj, e)ElseDim runDesigner As AnnRunDesigner = New AnnRunDesigner(Me.container)StartRunning(runDesigner, obj, e)End IfEnd IfEnd IfEnd SubPrivate Sub container_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)' see if a designer is currently running, if so, let it handle this eventIf Not currentDesigner Is Nothing Thene = New MouseEventArgs(InputManager.Current.PrimaryMouseDevice, e.Timestamp)currentDesigner.OnMouseMove(DirectCast(sender, AnnContainer), e)End IfEnd SubPrivate Sub container_MouseLeftButtonUp(ByVal sender As Object, ByVal e As MouseButtonEventArgs)' see if a designer is currently running, if so, let it handle this eventIf Not currentDesigner Is Nothing Thene = New MouseButtonEventArgs(InputManager.Current.PrimaryMouseDevice, e.Timestamp, MouseButton.Left)currentDesigner.OnMouseLeftButtonUp(DirectCast(sender, AnnContainer), e)End IfEnd SubPrivate Sub StartRunning(ByVal runDesigner As AnnRunDesigner, ByVal obj As AnnObject, ByVal e As MouseButtonEventArgs)' set up the current designerAddHandler runDesigner.Run, AddressOf OnDesignerRunrunDesigner.Object = objrunDesigner.Start()currentDesigner = runDesignere = New MouseButtonEventArgs(InputManager.Current.PrimaryMouseDevice, e.Timestamp, MouseButton.Left)currentDesigner.OnMouseLeftButtonUp(runDesigner.Container, e)End SubPrivate Sub OnDesignerRun(ByVal sender As Object, ByVal e As AnnRunDesignerEventArgs)' show information on the current edit operationConsole.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 boxIf e.Object.Hyperlink Is Nothing OrElse e.Object.Hyperlink = String.Empty ThenMessageBox.Show(String.Format("You clicked an object of type {0} that does not have a hyperlink", e.Object.GetType().Name))End IfEnd IfEnd SubEnd ClassPublic Sub AnnRunDesigner_AnnRunDesigner(ByVal title As String)Dim window As MyWindow1 = New MyWindow1(title)window.ShowDialog()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
using Leadtools.Windows.Controls;using Leadtools.Windows.Annotations;using Leadtools.Examples;//using Leadtools.Help;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// fix this path to an existing image file on your systemviewer = new ImageViewer();viewer.Source = new BitmapImage(new Uri(LeadtoolsExamples.Common.ImagesPath.Path + "ScarletMacaws.jpg"));viewer.Width = double.NaN;viewer.Height = double.NaN;// create and set up the containercontainer = 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 viewerviewer.Content = container;// Create a Panel to contain the controlsStackPanel panel = new StackPanel();panel.Children.Add(viewer);// set the viewer as a content of the windowthis.Content = panel;// add a few objects to the containerAnnRectangleObject 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 eventif (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 runningPoint pt = e.GetPosition(this.container);AnnObject obj = container.HitTest(pt);if (obj != null){// yes, start the run designer for this objectAnnRunDesigner 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 eventif (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 eventif (currentDesigner != null){currentDesigner.OnMouseLeftButtonUp(sender as AnnContainer, e);}}private void StartRunning(AnnRunDesigner runDesigner, AnnObject obj, MouseButtonEventArgs e){// set up the current designerrunDesigner.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 operationConsole.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 boxif (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();}
Imports Leadtools.Windows.ControlsImports Leadtools.Windows.AnnotationsPrivate Class MyWindow1 : Inherits ChildWindowPrivate container As AnnContainerPrivate viewer As ImageViewerPrivate currentDesigner As AnnDesignerPublic Sub New(ByVal title As String)Me.Title = titleMe.Width = 500Me.Height = 200' load an image into the viewerviewer = New ImageViewer()' fix this path to an existing image file on your systemviewer.Source =New BitmapImage(New Uri(LeadtoolsExamples.Common.ImagesPath.Path & "ScarletMacaws.jpg"))viewer.Width = Double.NaNviewer.Height = Double.NaN' create and set up the containercontainer = New AnnContainer()Dim bmp As BitmapSource = CType(viewer.Source, BitmapSource)container.Width = bmp.PixelWidthcontainer.Height = bmp.PixelHeightAddHandler container.MouseLeftButtonDown, AddressOf container_MouseLeftButtonDownAddHandler container.MouseMove, AddressOf container_MouseMoveAddHandler container.MouseLeftButtonUp, AddressOf container_MouseLeftButtonUp' Set the container as a content of viewerviewer.Content = container' Create a Panel to contain the controlsDim panel As StackPanel = New StackPanel()panel.Children.Add(viewer)' set the viewer as a content of the windowMe.Content = panel' add a few objects to the containerDim rectObj As AnnRectangleObject = New AnnRectangleObject()rectObj.Rect = New Rect(100, 100, 200, 200)rectObj.Stroke = Colors.BluerectObj.Fill = Colors.YellowrectObj.StrokeThickness = 2.0container.Children.Add(rectObj)End SubPrivate Sub container_MouseLeftButtonDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)' see if a designer is currently running, if so, let it handle this eventIf Not currentDesigner Is Nothing ThencurrentDesigner.OnMouseRightButtonDown(TryCast(sender, AnnContainer), e)End IfIf (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 runningDim 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 objectDim runDesigner As AnnRunDesigner = New AnnRunDesigner(Me.container)StartRunning(runDesigner, obj, e)End IfEnd IfEnd SubPrivate Sub container_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)' see if a designer is currently running, if so, let it handle this eventIf Not currentDesigner Is Nothing ThencurrentDesigner.OnMouseMove(TryCast(sender, AnnContainer), e)End IfEnd SubPrivate Sub container_MouseLeftButtonUp(ByVal sender As Object, ByVal e As MouseButtonEventArgs)' see if a designer is currently running, if so, let it handle this eventIf Not currentDesigner Is Nothing ThencurrentDesigner.OnMouseLeftButtonUp(TryCast(sender, AnnContainer), e)End IfEnd SubPrivate Sub StartRunning(ByVal runDesigner As AnnRunDesigner, ByVal obj As AnnObject, ByVal e As MouseButtonEventArgs)' set up the current designerAddHandler runDesigner.Run, AddressOf OnDesignerRunrunDesigner.Object = objrunDesigner.Start()currentDesigner = runDesignercurrentDesigner.OnMouseLeftButtonUp(runDesigner.Container, e)End SubPrivate Sub OnDesignerRun(ByVal sender As Object, ByVal e As AnnRunDesignerEventArgs)' show information on the current edit operationConsole.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 boxIf e.Object.Hyperlink Is Nothing OrElse e.Object.Hyperlink = String.Empty ThenMessageBox.Show(String.Format("You clicked an object of type {0} that does not have a hyperlink", e.Object.GetType().Name))End IfEnd IfEnd SubEnd ClassPublic Sub AnnRunDesigner_AnnRunDesigner(ByVal title As String)Dim window As MyWindow1 = New MyWindow1(title)window.Show()End Sub
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
