Start Visual Studio .NET. Choose File->New->Project… from the menu. In the New Project dialog box, choose either "Visual C# Projects" or "Visual Basic Projects" in the Projects Type List, and choose "Windows Application " in the Templates List. Type the project name as "Working With Automated Annotations" in the Project Name field, and then choose OK. If desired, type a new location for your project or select a directory using the Browse button, and then choose OK . In the "Solution Explorer" window, right-click on the "References" folder, and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and browse to Leadtools For .NET "\LEAD Technologies\LEADTOOLS 15\Bin\DotNet\Win32 " folder and select the following DLLs: Leadtools.dll Leadtools.Annotations.dll Leadtools.Codecs.dll Leadtools.WinForms.dll
Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and Drag and drop an instance of RasterImageViewer to the form. If you do not have RasterImageViewer in your toolbox, select Tools->Add Remove Toolbox Items from the menu. Click Browse and then select Leadtools.WinForms.DLL from "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Bin\DotNet\Win32" and then click Open and then click OK. Go to the toolbox (View->Toolbox) and Drag and drop 2 instances of RadioButton control to the bottom of the form, and set the following properties for them: Text Name Checked Design Mode radioButton1 True Run Mode radioButton2 False Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code ) and add the following lines at the beginning of the file: [Visual Basic]
[C#]Imports Leadtools Imports Leadtools.Annotations Imports Leadtools.Codecs Imports Leadtools.WinForms
using Leadtools; using Leadtools.Annotations; using Leadtools.Codecs; using Leadtools.WinForms;
Declare the following private variable: [Visual Basic]
[C#]' Automation Manager used in managing the automation mode. Private annAutomationManager As AnnAutomationManager
// Automation Manager used in managing the automation mode. private AnnAutomationManager annAutomationManager;
Add an event handler to the Form1 Load event and code it as follows: [Visual Basic]
[C#]Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load ' intitialize a new RasterCodecs object RasterCodecs.Startup() Dim codecs As New RasterCodecs() ' load the main image into our viewer rasterImageViewer1.Image = codecs.Load("C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Sample1.cmp") RasterCodecs.Shutdown() If (Not IsNothing(RasterImageViewer1.Image)) Then ' create and setup the automation manager annAutomationManager = New AnnAutomationManager ' Instruct the manager to create the default (all) automation objects. annAutomationManager.CreateDefaultObjects() ' create the toolbar and add it to the form annAutomationManager.CreateToolBar() Controls.Add(annAutomationManager.ToolBar) ' setup the automation (will create the container as well) Dim automation As AnnAutomation = New AnnAutomation(annAutomationManager, RasterImageViewer1) ' setup this automation as the active one automation.Active = True End If End Sub
private void Form1_Load(object sender, System.EventArgs e) { // intitialize a new RasterCodecs object RasterCodecs.Startup(); RasterCodecs codecs = new RasterCodecs(); // load the main image into our viewer rasterImageViewer1.Image = codecs.Load(@"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Sample1.cmp"); RasterCodecs.Shutdown(); if(rasterImageViewer1.Image != null) { // create and setup the automation manager annAutomationManager = new AnnAutomationManager(); // Instruct the manager to create the default (all) automation objects. annAutomationManager.CreateDefaultObjects(); // create the toolbar and add it to the form annAutomationManager.CreateToolBar(); Controls.Add(annAutomationManager.ToolBar); // setup the automation (will create the container as well) AnnAutomation automation = new AnnAutomation(annAutomationManager, rasterImageViewer1); // add an event handler for changes to the current designer automation.CurrentDesignerChanged += new EventHandler(automation_CurrentDesignerChanged); // setup this automation as the active one automation.Active = true; } }
Add an event handler to the radioButton1 CheckedChanged event and code it as follows: [Visual Basic]
[C#]Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged UserModeChanged(sender) End Sub
private void radioButton1_CheckedChanged(object sender, System.EventArgs e) { UserModeChanged(sender); }
Add an event handler to the radioButton2 CheckedChanged event and code it as follows: [Visual Basic]
[C#]Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged UserModeChanged(sender) End Sub
private void radioButton2_CheckedChanged(object sender, System.EventArgs e) { UserModeChanged(sender); }
Add the following function code to class Form1: [Visual Basic]
[C#]Private Sub UserModeChanged(ByVal sender As Object) If (Not IsNothing(annAutomationManager)) Then If (sender Is radioButton1) Then annAutomationManager.UserMode = AnnUserMode.Design Else annAutomationManager.UserMode = AnnUserMode.Run End If End If End Sub
private void UserModeChanged(object sender) { annAutomationManager.UserMode = (sender == radioButton1)?AnnUserMode.Design: AnnUserMode.Run; }
Add the following function code to class Form1: [Visual Basic]
[C#]' if the current designer is a button run designer, add a handler for Run Private Sub automation_CurrentDesignerChanged(ByVal sender As Object, ByVal e As EventArgs) Dim automation As AnnAutomation = DirectCast(sender, AnnAutomation) If (TypeOf (automation.CurrentDesigner) Is AnnButtonRunDesigner) Then Dim buttonRunDesigner As AnnButtonRunDesigner = DirectCast(automation.CurrentDesigner, AnnButtonRunDesigner) AddHandler buttonRunDesigner.Run, AddressOf buttonRunDesigner_Run End If End Sub Private Sub buttonRunDesigner_Run(ByVal sender As Object, ByVal e As AnnRunDesignerEventArgs) If (e.OperationStatus = AnnDesignerOperationStatus.End) Then Dim btn As AnnButtonObject = DirectCast(e.Object, AnnButtonObject) MessageBox.Show(String.Format("Button with text = {0} was clicked!", btn.Text)) End If End Sub
// if the current designer is a button run designer, add a handler for Run private void automation_CurrentDesignerChanged(object sender, EventArgs e) { AnnAutomation automation = sender as AnnAutomation; AnnButtonRunDesigner buttonRunDesigner = automation.CurrentDesigner as AnnButtonRunDesigner; if(buttonRunDesigner != null) buttonRunDesigner.Run += new EventHandler<AnnRunDesignerEventArgs>(buttonRunDesigner_Run); } private void buttonRunDesigner_Run(object sender, AnnRunDesignerEventArgs e) { if(e.OperationStatus == AnnDesignerOperationStatus.End) { AnnButtonObject btn = e.Object as AnnButtonObject; MessageBox.Show(string.Format("Button with text = {0} was clicked!", btn.Text)); } }
Build, and Run the program to test it. You can now select objects from the toolbar, draw objects on top of the image, select the objects and move/change them. Right-click on any object to show its properties, etc. Create an audio annotation. Right-click on the annotation and set the file to any .wav file available on your system. Create a button annotation. Right-click on the annotation and change any of the button properties you wish. Select Run Mode Radio button, As you move the cursor over the audio annotation and the button annotation, the cursor changes to a hand. Click on the audio annotation to hear the .wav file. Click on the button annotation to call the program listed in the Hyperlink field.