Implementing a Non Automated Annotation Program

Take the following steps to create and run a program that implements non-automated annotations:

  1. Start Visual Studio.

  2. Choose File->New->Project… from the menu.

  3. 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.

  4. 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.

  5. 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:

    • Leadtools.dll
    • Leadtools.Annotations.Engine.dll
    • Leadtools.Annotations.Rendering.WinForms.dll
    • Leadtools.Codecs.dll
    • Leadtools.Codecs.Cmp.dll
    • Leadtools.Controls.WinForms.dll

    Click Add and then click OK to add the above DLLs to the application.

  6. 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.

  7. Change the following properties:

    Property Value
    Dock Fill
  8. 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:

    VB
    Imports Leadtools 
    Imports Leadtools.Annotations.Engine 
    Imports Leadtools.Annotations.Rendering 
    Imports Leadtools.Codecs 
    Imports Leadtools.Controls.WinForms 
    C#
    using Leadtools; 
    using Leadtools.Annotations.Engine; 
    using Leadtools.Annotations.Rendering; 
    using Leadtools.Codecs; 
    using Leadtools.Controls.WinForms; 

  9. Declare the following private variable:

    VB
    ' Annotation container object 
    Private annContainerObj As AnnContainer 
    ' Annotation Rendering Engine 
    private renderingEngine As AnnWinFormsRenderingEngine 
    C#
    // Annotation container object 
    private AnnContainer annContainerObj; 
    // Annotation Rendering Engine 
    private AnnWinFormsRenderingEngine renderingEngine; 

  10. Add an event handler to the Form1 Load event and code it as follows:

    VB
    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    
    C#
    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(); 
       } 
    } 

  11. Add an event handler to the rasterImageViewer1 PostImagePaint event and code it as follows:

    VB
    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    
    C#
    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(); 
      } 
    }  

  12. Add the CreateAnnNoteObject function code to class Form1:

    VB
    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  
    C#
    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; 
    } 

  13. Build, and run the program to test it.
Help Version 20.0.2020.4.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Imaging, Medical, and Document