The base class for all the designers in the annotation toolkit.
public abstract class AnnDesigner Public MustInherit Class AnnDesigner
public ref class AnnDesigner abstract 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 must assign an AnnContainer object to the Container member and either a Leadtools.WinForms.RasterImageViewer object to the Owner, or an IAnnAutomationControl to the AutomationControl members of the 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.
Refer to IAnnAutomationControl for an example on how to use LEADTOOLS annotations with your own controls.
using Leadtools;using Leadtools.Annotations;using Leadtools.Codecs;using Leadtools.WinForms;/// Shows how to use designers to create and select annotation objectsclass 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 viewercodecs = new RasterCodecs();string fileName = Path.Combine(LEAD_VARS.ImagesDir, "image1.cmp");viewer.Image = codecs.Load(fileName);// create and set up the containercontainer = 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 buttonsPanel panel = new Panel();panel.Dock = DockStyle.Left;Controls.Add(panel);panel.BringToFront();// Create three buttonsButton 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 viewerviewer.Dock = DockStyle.Fill;Controls.Add(viewer);viewer.BringToFront();}private void viewer_TransformChanged(object sender, EventArgs e){// set up the container transformationif (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 viewerif (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 runningif (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 designerAnnLineDrawDesigner 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 designerAnnRectangleDrawDesigner 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 designerif (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 designerdrawDesigner.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 operationConsole.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 eventif (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 editingAnnPoint pt = new AnnPoint(e.X, e.Y);AnnObject obj = container.HitTest(pt, 2);if (obj != null){// yes, start the edit designer for this objectif (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 designersEndDesigner();// set up the current designereditDesigner.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 pointsAnnRectangleControlPoint 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 operationConsole.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);elseConsole.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 eventif (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 eventif (currentDesigner != null)handled = currentDesigner.MouseUp(e);}private void viewer_LostFocus(object sender, EventArgs e){// see if a designer is currently running, if so, cancel itif (currentDesigner != null)currentDesigner.Cancel();}}public void AnnDesigner_AnnDesigner(string title){MyForm1 form = new MyForm1(title);form.ShowDialog();}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
Imports LeadtoolsImports Leadtools.AnnotationsImports Leadtools.CodecsImports Leadtools.WinForms''' Shows how to use designers to create and select annotation objectsPrivate Class MyForm1 : Inherits FormPrivate myAnnContainer As AnnContainer'AnnAutomationManager manager;Private viewer As RasterImageViewerPrivate codecs As RasterCodecsPrivate currentDesigner As AnnDesignerPublic Sub New(ByVal title As String)Text = titleSize = New Size(500, 200)viewer = New RasterImageViewer()AddHandler viewer.TransformChanged, AddressOf viewer_TransformChangedAddHandler viewer.PostImagePaint, AddressOf viewer_PostImagePaintAddHandler viewer.MouseDown, AddressOf viewer_MouseDownAddHandler viewer.MouseMove, AddressOf viewer_MouseMoveAddHandler viewer.MouseUp, AddressOf viewer_MouseUpAddHandler viewer.LostFocus, AddressOf viewer_LostFocus' load an image into the viewercodecs = 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 containermyAnnContainer = 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 buttonsDim panel As Panel = New Panel()panel.Dock = DockStyle.LeftControls.Add(panel)panel.BringToFront()' Create three buttonsDim buttonLine As Button = New Button()AddHandler buttonLine.Click, AddressOf buttonLine_ClickbuttonLine.Text = "Line"buttonLine.Dock = DockStyle.Toppanel.Controls.Add(buttonLine)buttonLine.BringToFront()Dim buttonRectangle As Button = New Button()AddHandler buttonRectangle.Click, AddressOf buttonRectangle_ClickbuttonRectangle.Text = "Rectangle"buttonRectangle.Dock = DockStyle.Bottompanel.Controls.Add(buttonRectangle)buttonRectangle.BringToFront()Dim buttonSelect As Button = New Button()AddHandler buttonSelect.Click, AddressOf buttonSelect_ClickbuttonSelect.Text = "Select"buttonSelect.Dock = DockStyle.Leftpanel.Controls.Add(buttonSelect)buttonSelect.BringToFront()' Add the viewerviewer.Dock = DockStyle.FillControls.Add(viewer)viewer.BringToFront()End SubPrivate Sub viewer_TransformChanged(ByVal sender As Object, ByVal e As EventArgs)' set up the container transformationIf Not viewer.Image Is Nothing AndAlso Not myAnnContainer Is Nothing ThenmyAnnContainer.Transform = viewer.Transform.Clone()End IfEnd SubPrivate Sub viewer_PostImagePaint(ByVal sender As Object, ByVal e As PaintEventArgs)' draw the container and its objects on this viewerIf Not viewer.Image Is Nothing AndAlso Not myAnnContainer Is Nothing ThenmyAnnContainer.Draw(e.Graphics)End IfEnd SubPrivate Sub buttonSelect_Click(ByVal sender As Object, ByVal e As System.EventArgs)' Select button is clicked' cancel any draw designer runningIf Not currentDesigner Is Nothing AndAlso TypeOf currentDesigner Is AnnDrawDesigner ThenDim drawDesigner As AnnDrawDesigner = CType(IIf(TypeOf currentDesigner Is AnnDrawDesigner, currentDesigner, Nothing), AnnDrawDesigner)drawDesigner.Cancel()currentDesigner = NothingEnd IfEnd SubPrivate 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 designerDim 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 = lineObjectStartDrawDesigner(lineDrawDesigner)End SubPrivate 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 designerDim 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 = rectangleObjectStartDrawDesigner(rectangleDrawDesigner)End SubPrivate Sub EndDesigner()' ends any running designerIf Not currentDesigner Is Nothing ThenIf TypeOf currentDesigner Is AnnEditDesigner ThenDim editDesigner As AnnEditDesigner = CType(IIf(TypeOf currentDesigner Is AnnEditDesigner, currentDesigner, Nothing), AnnEditDesigner)editDesigner.End()ElseIf TypeOf currentDesigner Is AnnDrawDesigner ThenDim drawDesigner As AnnDrawDesigner = CType(IIf(TypeOf currentDesigner Is AnnDrawDesigner, currentDesigner, Nothing), AnnDrawDesigner)drawDesigner.Cancel()End IfEnd IfEnd SubPrivate Sub StartDrawDesigner(ByVal drawDesigner As AnnDrawDesigner)' set up the current designerAddHandler drawDesigner.Draw, AddressOf OnDesignerDrawdrawDesigner.Owner = viewerdrawDesigner.ClipCursor = TruedrawDesigner.Container = myAnnContainercurrentDesigner = drawDesignerEnd SubPrivate Sub OnDesignerDraw(ByVal sender As Object, ByVal e As AnnDrawDesignerEventArgs)' show information on the current draw operationConsole.Write("Status: {0}, Object: {1}, Coordinates:", e.OperationStatus, e.Object.GetType().Name)If TypeOf e.Object Is AnnLineObject ThenDim 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 ThenDim rectangleObject As AnnRectangleObject = CType(IIf(TypeOf e.Object Is AnnRectangleObject, e.Object, Nothing), AnnRectangleObject)Console.WriteLine("Bounds: {0}", rectangleObject.Bounds)End IfEnd SubPrivate 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 eventIf Not currentDesigner Is Nothing Thenhandled = currentDesigner.MouseDown(e)End IfIf (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 editingDim 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 objectIf TypeOf obj Is AnnLineObject ThenDim lineEditDesigner As AnnLineEditDesigner = New AnnLineEditDesigner()StartEditing(lineEditDesigner, obj, pt)lineEditDesigner.MouseDown(e)ElseIf TypeOf obj Is AnnRectangleObject ThenDim rectangleEditDesigner As AnnRectangleEditDesigner = New AnnRectangleEditDesigner()StartEditing(rectangleEditDesigner, obj, pt)rectangleEditDesigner.MouseDown(e)End IfEnd IfEnd IfEnd SubPrivate Sub StartEditing(ByVal editDesigner As AnnEditDesigner, ByVal obj As AnnObject, ByVal pt As AnnPoint)' first end any running designersEndDesigner()' set up the current designerAddHandler editDesigner.Edit, AddressOf OnDesignerEditeditDesigner.Owner = viewereditDesigner.Container = myAnnContainereditDesigner.ClipCursor = TrueeditDesigner.EditObject = objeditDesigner.HitTestBuffer = 2editDesigner.ControlPointsHitTestBuffer = 2editDesigner.RotateModifierKey = Keys.ShifteditDesigner.HitTestObject = obj.HitTest(pt, 2)' set up the edit designer control pointsDim 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 = 0Do While i < editDesigner.ControlPointCounteditDesigner.ControlPoints(i) = rectangleControlPointi += 1LoopeditDesigner.Start()currentDesigner = editDesignerEnd SubPrivate Sub OnDesignerEdit(ByVal sender As Object, ByVal e As AnnEditDesignerEventArgs)' show information on the current draw operationConsole.Write("Object: {0}, Operation: {1}, Status: {2}, ", e.Object.GetType().Name, e.Operation, e.OperationStatus)If e.Operation = AnnEditDesignerOperation.MoveControlPoint ThenConsole.WriteLine("Control Point index: {0}", e.MoveControlPointIndex)ElseConsole.WriteLine("HitTestObject: {0}", e.HitTestObject)End IfEnd SubPrivate 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 eventIf Not currentDesigner Is Nothing Thenhandled = currentDesigner.MouseMove(e)End IfEnd SubPrivate 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 eventIf Not currentDesigner Is Nothing Thenhandled = currentDesigner.MouseUp(e)End IfEnd SubPrivate Sub viewer_LostFocus(ByVal sender As Object, ByVal e As EventArgs)' see if a designer is currently running, if so, cancel itIf Not currentDesigner Is Nothing ThencurrentDesigner.Cancel()End IfEnd SubEnd ClassPublic Sub AnnDesigner_AnnDesigner(ByVal title As String)Dim form As MyForm1 = New MyForm1(title)form.ShowDialog()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
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
