Take the following steps to create and run a program that implements non-automated annotations:
Start Visual Studio.
Choose File->New->Project… from the menu.
In the New Project dialog box, choose either "Visual C# Projects" or "VB Projects" in the Projects Type List, and choose "Windows Forms Application" in the Templates List.
Type the project name as "Implementing Non-Automated Annotations" in the Name field, and then click OK. If desired, type a new location for your project or select a directory using the Browse button, and then click OK.
In the "Solution Explorer" window, right-click the "References" folder, and choose "Add Reference…" from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and browse to Leadtools For .NET "<LEADTOOLS_INSTALLDIR>\Bin\DotNet4\Win32" folder and select the following DLLs:
Click Add and then click OK to add the above DLLs to the application.
Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and Drag and drop an instance of the ImageViewer control onto the form. If you do not have the ImageViewer in your toolbox, choose Tools->Choose Toolbox Items from the menu. Click Browse and then select the Leadtools.Controls.WinForms.DLL from the "<LEADTOOLS_INSTALLDIR>\Bin\DotNet4\Win32" directory. Next, click Open and then click OK.
Change the following properties:
| Property | Value |
| Dock | Fill |
Switch to Form1 code view (right-click Form1 in the Solution Explorer and then select View Code) and add the following lines at the beginning of the file:
Imports LeadtoolsImports Leadtools.Annotations.EngineImports Leadtools.Annotations.RenderingImports Leadtools.CodecsImports Leadtools.Controls.WinForms
using Leadtools;using Leadtools.Annotations.Engine;using Leadtools.Annotations.Rendering;using Leadtools.Codecs;using Leadtools.Controls.WinForms;
Declare the following private variable:
' Annotation container objectPrivate annContainerObj As AnnContainer' Annotation Rendering Engineprivate renderingEngine As AnnWinFormsRenderingEngine
// Annotation container objectprivate AnnContainer annContainerObj;// Annotation Rendering Engineprivate AnnWinFormsRenderingEngine renderingEngine;
Add an event handler to the Form1 Load event and code it as follows:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load' initialize a new RasterCodecs objectDim codecs As New RasterCodecs()' load the main image into our viewerRasterImageViewer1.Image = codecs.Load("C:\Users\Public\Documents\LEADTOOLS Images\Sample1.cmp")RasterImageViewer1.Zoom(ControlSizeMode.Fit, RasterImageViewer1.ScaleFactor, RasterImageViewer1.DefaultZoomOrigin)If (Not IsNothing(RasterImageViewer1.Image)) Then' initialize the AnnContainer object and associate it with RasterImageViewer1 imageannContainerObj = New AnnContainer' create Annotation Note Object and add it to the containerannContainerObj.Children.Add(CreateAnnNoteObject(New LeadRectD(10, 10, 500, 500)))' initialize the RenderingEnginerenderingEngine = New AnnWinFormsRenderingEngine()End IfEnd Sub
private void Form1_Load(object sender, System.EventArgs e){// initialize a new RasterCodecs objectRasterCodecs codecs = new RasterCodecs();// load the main image into our viewerrasterImageViewer1.Image = codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\Sample1.cmp");rasterImageViewer1.Zoom(ControlSizeMode.Fit, rasterImageViewer1.ScaleFactor, rasterImageViewer1.DefaultZoomOrigin);if(rasterImageViewer1.Image != null){// initialize the AnnContainer object and associate it with the rasterImageViewer1 imageannContainerObj = new AnnContainer();// create an Annotation Note object and add it to the containerannContainerObj.Children.Add(CreateAnnNoteObject(new LeadRectD(10, 10, 500, 500)));// initialize the RenderingEnginerenderingEngine = new AnnWinFormsRenderingEngine();}}
Add an event handler to the rasterImageViewer1 PostImagePaint event and code it as follows:
Private Sub RasterImageViewer1_PostImagePaint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) _Handles RasterImageViewer1.PostImagePaintIf (Not IsNothing(annContainerObj)) ThenrenderingEngine.Attach(annContainerObj, e.Graphics)renderingEngine.Render(LeadRectD.Empty, true)renderingEngine.Detach()End IfEnd Sub
private void rasterImageViewer1_PostImagePaint(object sender, System.Windows.Forms.PaintEventArgs e){if (annContainerObj != null){renderingEngine.Attach(annContainerObj, e.Graphics);renderingEngine.Render(LeadRectD.Empty, true);renderingEngine.Detach();}}
Add the CreateAnnNoteObject function code to class Form1:
Private Function CreateAnnNoteObject(ByVal boundingRect As LeadRectD) As AnnObjectDim annNoteObj As AnnNoteObject = New AnnNoteObjectannNoteObj.Text = "This is my Text"annNoteObj.Font = New AnnFont("Arial", 14)annNoteObj.Hyperlink = "Notepad.exe"annNoteObj.Rect = boundingRectReturn annNoteObjEnd Function
private AnnObject CreateAnnNoteObject(LeadRectD boundingRect){AnnNoteObject annNoteObj = new AnnNoteObject();annNoteObj.Text = "This is my Text";annNoteObj.Font = new AnnFont("Arial", 14);annNoteObj.Hyperlink = "Notepad.exe";annNoteObj.Rect = boundingRect;return annNoteObj;}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
