Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction | Help Version 19.0.6.22
|
Note: Leadtools.Annotations.WinForms.dll is the result of compiling the example project shipped with source code at <LEADTOOLS_INSTALLDIR>\Examples\DotNet\CS\Leadtools.Annotations.WinForms. The LEADTOOLS setup copies a precompiled version of this assembly into the Bin\DotNet4 folder. This assembly contains .NET WinForms annotations automation user-interface helper classes such as AnnAutomationRasterImageViewer and AnnAutomationManagerHelper.
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.WinForms;
// Annotations-aware RasterImageViewer
private AnnAutomationRasterImageViewer _imageViewer;
// Annotations automation manager with WinForms functionality
private AnnAutomationManagerHelper _annotations;
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);
}