Take the following steps to create and run a program that implements non-automated annotations:
Start Visual Studio .NET.
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.Core
Imports Leadtools.Annotations.Rendering
Imports Leadtools.Codecs
Imports Leadtools.Controls.WinForms
using Leadtools;
using Leadtools.Annotations.Core;
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;
}
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET