Visual Basic (Declaration) | |
---|---|
Public Class AnnAutomationManager Implements IDisposable |
Visual Basic (Usage) | Copy Code |
---|---|
Dim instance As AnnAutomationManager |
C# | |
---|---|
public class AnnAutomationManager : IDisposable |
C++/CLI | |
---|---|
public ref class AnnAutomationManager : public IDisposable |
This example creates an automated annotation application. This example will only use the line and rectangle objects. The example lets you select objects from the toolbar, draw objects on top of the image, select objects and move them or change them, right click on any object to show its properties, etc.
Visual Basic | Copy Code |
---|---|
Private Class MyForm1 : Inherits Form Private manager As AnnAutomationManager Private viewer As RasterImageViewer Private codecs As RasterCodecs Public Sub New(ByVal title As String) Text = title Size = New Size(400, 400) viewer = New RasterImageViewer() viewer.Dock = DockStyle.Fill Controls.Add(viewer) viewer.BringToFront() ' 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 automation manager manager = New AnnAutomationManager() ' Create only the line and rectangle automation objects CreateMyAutomationObjects(manager) ' You can instruct the manager to create the default (all) automation objects. ' comment out the call to CreateMyAutomationObjects and call this instead: 'theManager.CreateDefaultObjects(); ' Disable some of the property dialogs ' In this case, we hide the 'Hyperlink' and 'Fixed' annotation property pages manager.HidePropertiesTabs = AnnAutomationHidePropertiesTabs.Hyperlink Or AnnAutomationHidePropertiesTabs.Fixed ' create the toolbar and add it to the form manager.CreateToolBar() Controls.Add(manager.ToolBar) ' set up the automation (will create the container as well) Dim automation As AnnAutomation = New AnnAutomation(manager, viewer) ' set up this automation as the active one automation.Active = True End Sub Private Sub CreateMyAutomationObjects(ByVal manager As AnnAutomationManager) ' set up the select automation object Dim selObj As AnnAutomationObject = New AnnAutomationObject() selObj.Id = AnnAutomationManager.SelectObjectId selObj.Name = "Select" selObj.Object = Nothing selObj.DrawDesignerType = Nothing selObj.EditDesignerType = Nothing selObj.RunDesignerType = Nothing ' create the toolbar button (or you can load the image from a disk file or resource) Dim btmp As Bitmap = New Bitmap(16, 16) Dim g As Graphics = Graphics.FromImage(btmp) Try g.FillRectangle(SystemBrushes.Control, New Rectangle(0, 0, 16, 16)) g.DrawLine(Pens.Black, 4, 4, 12, 12) g.DrawLine(Pens.Black, 4, 12, 12, 4) Finally CType(g, IDisposable).Dispose() End Try selObj.ToolBarImage = btmp selObj.ToolBarToolTipText = "Select" selObj.DrawCursor = Cursors.Default selObj.ContextMenu = Nothing manager.Objects.Add(selObj) ' set up the line automation object Dim lineObj As AnnAutomationObject = New AnnAutomationObject() lineObj.Id = AnnAutomationManager.LineObjectId lineObj.Name = "Line" Dim line As AnnLineObject = New AnnLineObject() line.Pen = New AnnPen(Color.Red, New AnnLength(1, AnnUnit.Pixel)) lineObj.Object = line lineObj.DrawDesignerType = GetType(AnnLineDrawDesigner) lineObj.EditDesignerType = GetType(AnnLineEditDesigner) lineObj.RunDesignerType = GetType(AnnRunDesigner) btmp = New Bitmap(16, 16) g = Graphics.FromImage(btmp) Try g.FillRectangle(SystemBrushes.Control, New Rectangle(0, 0, 16, 16)) g.DrawLine(Pens.Black, 4, 12, 12, 4) Finally CType(g, IDisposable).Dispose() End Try lineObj.ToolBarImage = btmp lineObj.ToolBarToolTipText = "Draw new line object" lineObj.DrawCursor = Cursors.Cross lineObj.ContextMenu = AnnAutomationManager.CreateDefaultObjectContextMenu(lineObj.Id) manager.Objects.Add(lineObj) ' set up the rectangle automation object Dim rectObj As AnnAutomationObject = New AnnAutomationObject() rectObj.Id = AnnAutomationManager.RectangleObjectId rectObj.Name = "Rectangle" Dim rect As AnnRectangleObject = New AnnRectangleObject() rect.Pen = New AnnPen(Color.Red, New AnnLength(1, AnnUnit.Pixel)) rect.Brush = New AnnSolidBrush(Color.White) rectObj.Object = rect rectObj.DrawDesignerType = GetType(AnnRectangleDrawDesigner) rectObj.EditDesignerType = GetType(AnnRectangleEditDesigner) rectObj.RunDesignerType = GetType(AnnRunDesigner) btmp = New Bitmap(16, 16) g = Graphics.FromImage(btmp) Try g.FillRectangle(SystemBrushes.Control, New Rectangle(0, 0, 16, 16)) g.DrawRectangle(Pens.Black, 2, 4, 10, 8) Finally CType(g, IDisposable).Dispose() End Try rectObj.ToolBarImage = btmp rectObj.ToolBarToolTipText = "Draw new rectangle object" rectObj.DrawCursor = Cursors.Cross rectObj.ContextMenu = AnnAutomationManager.CreateDefaultObjectContextMenu(rectObj.Id) manager.Objects.Add(rectObj) ' set up the group automation object (always needed) Dim groupObj As AnnAutomationObject = New AnnAutomationObject() groupObj.Id = AnnAutomationManager.GroupObjectId groupObj.Name = "Group" groupObj.Object = New AnnGroupObject() groupObj.DrawDesignerType = Nothing groupObj.EditDesignerType = GetType(AnnNewGroupEditDesigner) groupObj.RunDesignerType = GetType(AnnRunDesigner) groupObj.ToolBarImage = Nothing ' group is not in the toolbar groupObj.ToolBarToolTipText = Nothing groupObj.DrawCursor = Nothing groupObj.ContextMenu = AnnAutomationManager.CreateDefaultObjectContextMenu(groupObj.Id) manager.Objects.Add(groupObj) End Sub End Class Public Sub AnnAutomationManager_AnnAutomationManager(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 { AnnAutomationManager manager; RasterImageViewer viewer; RasterCodecs codecs; public MyForm1(string title) { Text = title; Size = new Size(400, 400); viewer = new RasterImageViewer(); viewer.Dock = DockStyle.Fill; Controls.Add(viewer); viewer.BringToFront(); // 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 automation manager manager = new AnnAutomationManager(); // Create only the line and rectangle automation objects CreateMyAutomationObjects(manager); // You can instruct the manager to create the default (all) automation objects. // comment out the call to CreateMyAutomationObjects and call this instead: //theManager.CreateDefaultObjects(); // Disable some of the property dialogs // In this case, we hide the 'Hyperlink' and 'Fixed' annotation property pages manager.HidePropertiesTabs = AnnAutomationHidePropertiesTabs.Hyperlink | AnnAutomationHidePropertiesTabs.Fixed; // create the toolbar and add it to the form manager.CreateToolBar(); Controls.Add(manager.ToolBar); // set up the automation (will create the container as well) AnnAutomation automation = new AnnAutomation(manager, viewer); // set up this automation as the active one automation.Active = true; } private void CreateMyAutomationObjects(AnnAutomationManager manager) { // set up the select automation object AnnAutomationObject selObj = new AnnAutomationObject(); selObj.Id = AnnAutomationManager.SelectObjectId; selObj.Name = "Select"; selObj.Object = null; selObj.DrawDesignerType = null; selObj.EditDesignerType = null; selObj.RunDesignerType = null; // create the toolbar button (or you can load the image from a disk file or resource) Bitmap btmp = new Bitmap(16, 16); using(Graphics graphics = Graphics.FromImage(btmp)) { graphics.FillRectangle(SystemBrushes.Control, new Rectangle(0, 0, 16, 16)); graphics.DrawLine(Pens.Black, 4, 4, 12, 12); graphics.DrawLine(Pens.Black, 4, 12, 12, 4); } selObj.ToolBarImage = btmp; selObj.ToolBarToolTipText = "Select"; selObj.DrawCursor = Cursors.Default; selObj.ContextMenu = null; manager.Objects.Add(selObj); // set up the line automation object AnnAutomationObject lineObj = new AnnAutomationObject(); lineObj.Id = AnnAutomationManager.LineObjectId; lineObj.Name = "Line"; AnnLineObject line = new AnnLineObject(); line.Pen = new AnnPen(Color.Red, new AnnLength(1, AnnUnit.Pixel)); lineObj.Object = line; lineObj.DrawDesignerType = typeof(AnnLineDrawDesigner); lineObj.EditDesignerType = typeof(AnnLineEditDesigner); lineObj.RunDesignerType = typeof(AnnRunDesigner); btmp = new Bitmap(16, 16); using(Graphics graphics = Graphics.FromImage(btmp)) { graphics.FillRectangle(SystemBrushes.Control, new Rectangle(0, 0, 16, 16)); graphics.DrawLine(Pens.Black, 4, 12, 12, 4); } lineObj.ToolBarImage = btmp; lineObj.ToolBarToolTipText = "Draw new line object"; lineObj.DrawCursor = Cursors.Cross; lineObj.ContextMenu = AnnAutomationManager.CreateDefaultObjectContextMenu(lineObj.Id); manager.Objects.Add(lineObj); // set up the rectangle automation object AnnAutomationObject rectObj = new AnnAutomationObject(); rectObj.Id = AnnAutomationManager.RectangleObjectId; rectObj.Name = "Rectangle"; AnnRectangleObject rect = new AnnRectangleObject(); rect.Pen = new AnnPen(Color.Red, new AnnLength(1, AnnUnit.Pixel)); rect.Brush = new AnnSolidBrush(Color.White); rectObj.Object = rect; rectObj.DrawDesignerType = typeof(AnnRectangleDrawDesigner); rectObj.EditDesignerType = typeof(AnnRectangleEditDesigner); rectObj.RunDesignerType = typeof(AnnRunDesigner); btmp = new Bitmap(16, 16); using(Graphics graphics = Graphics.FromImage(btmp)) { graphics.FillRectangle(SystemBrushes.Control, new Rectangle(0, 0, 16, 16)); graphics.DrawRectangle(Pens.Black, 2, 4, 10, 8); } rectObj.ToolBarImage = btmp; rectObj.ToolBarToolTipText = "Draw new rectangle object"; rectObj.DrawCursor = Cursors.Cross; rectObj.ContextMenu = AnnAutomationManager.CreateDefaultObjectContextMenu(rectObj.Id); manager.Objects.Add(rectObj); // set up the group automation object (always needed) AnnAutomationObject groupObj = new AnnAutomationObject(); groupObj.Id = AnnAutomationManager.GroupObjectId; groupObj.Name = "Group"; groupObj.Object = new AnnGroupObject(); groupObj.DrawDesignerType = null; groupObj.EditDesignerType = typeof(AnnNewGroupEditDesigner); groupObj.RunDesignerType = typeof(AnnRunDesigner); groupObj.ToolBarImage = null; // group is not in the toolbar groupObj.ToolBarToolTipText = null; groupObj.DrawCursor = null; groupObj.ContextMenu = AnnAutomationManager.CreateDefaultObjectContextMenu(groupObj.Id); manager.Objects.Add(groupObj); } } public void AnnAutomationManager_AnnAutomationManager(string title) { MyForm1 form = new MyForm1(title); form.ShowDialog(); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; } |
The AnnAutomationManager class holds the collection of all AnnAutomation objects in the application as well the annotation toolbar. Cursor, keyboard, context sensitive menus, property dialogs and various other user interface options and settings are stored here as well.
An automated annotation application usually creates one AnnAutomationManager object per application.
System.Object
Leadtools.Annotations.AnnAutomationManager
Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7