Take the following steps to start a project and to add some code that will demonstrate the automated annotation features of the LEADTOOLS Windows Forms Annotations.
In the "Solution Explorer" window, right-click on the "References" folder for the project and select "Add Reference..." from the context menu. In the "Reference Manager" dialog box, select Browse to the "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet4\" folder (depending on your target platform), and select the following assembly files:
Leadtools.dllLeadtools.Codecs.dllLeadtools.Drawing.dllLeadtools.WinForms.dllLeadtools.Codecs.Bmp.dllLeadtools.Codecs.Fax.dllLeadtools.Codecs.Tif.dllLeadtools.Codecs.Cmp.dllLeadtools.Codecs.Png.dllLeadtools.Annotations.Core.dllLeadtools.Annotations.Designers.dllLeadtools.Annotations.Rendering.dllLeadtools.Annotations.Automation.dllLeadtools.Annotations.Automation.WinForms.dll
Click the Select button and then press the OK button to add the above references to the application.
If you are using .NET 4, then this application will required switching the Target framework to full .NET Framework 4.
Switch to code view of the main form and add the following declerations at the top:
[C#]
using Leadtools;
using Leadtools.WinForms;
using Leadtools.Codecs;
using Leadtools.Annotations.Core;
using Leadtools.Annotations.Designers;
using Leadtools.Annotations.Rendering;
using Leadtools.Annotations.Automation;
using Leadtools.Annotations.Automation.WinForms;
Add the following private members to Form1:
[C#]
// Annotations-aware RasterImageViewer
private AnnAutomationRasterImageViewer _imageViewer;
// Annotations automation manager with WinForms functionality
private AnnAutomationManagerHelper _annotations;
Add the following code to in Form1 Load event. This will create a minimum automation application:
[C#]
protected override void OnLoad(EventArgs e)
{
if (!DesignMode)
{
// Create the viewer and add it to the form
_imageViewer = new AnnAutomationRasterImageViewer();
_imageViewer.Dock = DockStyle.Fill;
Controls.Add(_imageViewer);
// Create the annotations
AnnAutomationManager automationManager = new AnnAutomationManager();
automationManager.CreateDefaultObjects();
// Create the helper
_annotations = new AnnAutomationManagerHelper(automationManager);
// Create the toolbar and add it to our form
_annotations.CreateToolBar();
ToolBar toolBar = _annotations.ToolBar;
toolBar.Dock = DockStyle.Top;
toolBar.Appearance = ToolBarAppearance.Flat;
Controls.Add(toolBar);
// Load an image into the viewer
using (RasterCodecs codecs = new RasterCodecs())
_imageViewer.Image = codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\sample1.cmp");
// Create an automation object for it
AnnAutomation automation = new AnnAutomation(automationManager, _imageViewer);
automationManager.Automations.Add(automation);
// Add the events to show the object context menu and object properties form
automation.OnShowContextMenu += delegate(object sender, AnnAutomationEventArgs showContextMenuEventArgs)
{
if (showContextMenuEventArgs != null && showContextMenuEventArgs.Object != null)
{
AnnAutomationObjectExtData data = showContextMenuEventArgs.Object.UserData as AnnAutomationObjectExtData;
if (data != null && data.ContextMenu != null)
{
ObjectContextMenu menu = data.ContextMenu as ObjectContextMenu;
if (menu != null)
{
menu.Automation = sender as AnnAutomation;
data.ContextMenu.Show(this, _imageViewer.PointToClient(Cursor.Position));
}
}
}
};
automation.OnShowObjectProperties += delegate(object sender, EventArgs showObjectPropertiesEventArgs)
{
// Show the object properties form
using (ObjectPropertiesForm form = new ObjectPropertiesForm(automation))
{
try
{
form.ShowDialog(this);
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message);
}
}
};
// Set it as Active so UI input will go to it
automation.Active = true;
}
base.OnLoad(e);
}
Build and run the demo. You should be able to annotate the image, right click on any object to show the context menu, select properties to change any object properties.