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 Leadtools
Imports Leadtools.Annotations.Engine
Imports Leadtools.Annotations.Rendering
Imports Leadtools.Codecs
Imports 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 object
Private annContainerObj As AnnContainer
' Annotation Rendering Engine
private renderingEngine As AnnWinFormsRenderingEngine
// Annotation container object
private AnnContainer annContainerObj;
// Annotation Rendering Engine
private 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 object
Dim codecs As New RasterCodecs()
' load the main image into our viewer
RasterImageViewer1.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 image
annContainerObj = New AnnContainer
' create Annotation Note Object and add it to the container
annContainerObj.Children.Add(CreateAnnNoteObject(New LeadRectD(10, 10, 500, 500)))
' initialize the RenderingEngine
renderingEngine = New AnnWinFormsRenderingEngine()
End If
End Sub
private void Form1_Load(object sender, System.EventArgs e)
{
// initialize a new RasterCodecs object
RasterCodecs codecs = new RasterCodecs();
// load the main image into our viewer
rasterImageViewer1.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 image
annContainerObj = new AnnContainer();
// create an Annotation Note object and add it to the container
annContainerObj.Children.Add(CreateAnnNoteObject(new LeadRectD(10, 10, 500, 500)));
// initialize the RenderingEngine
renderingEngine = 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.PostImagePaint
If (Not IsNothing(annContainerObj)) Then
renderingEngine.Attach(annContainerObj, e.Graphics)
renderingEngine.Render(LeadRectD.Empty, true)
renderingEngine.Detach()
End If
End 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 AnnObject
Dim annNoteObj As AnnNoteObject = New AnnNoteObject
annNoteObj.Text = "This is my Text"
annNoteObj.Font = New AnnFont("Arial", 14)
annNoteObj.Hyperlink = "Notepad.exe"
annNoteObj.Rect = boundingRect
Return annNoteObj
End 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
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.