Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.12.21
Implementing Non Automated Annotation Program
Take the following steps to create and run a program that implements non-automated annotations:
  1. Start Visual Studio .NET.
  2. Choose File->New->Project… from the menu.
  3. In the New Project dialog box, choose either "Visual C# Projects" or "Visual Basic Projects" in the Projects Type List, and choose "Windows Application " in the Templates List.
  4. Type the project name as "Implementing Non Automated Annotation" in the Project Name field, and then choose OK. If desired, type a new location for your project or select a directory using the Browse button, and then choose OK .
  5. In the "Solution Explorer" window, right-click on the "References" folder, and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and browse to Leadtools For .NET "\LEAD Technologies\LEADTOOLS 15\Bin\DotNet\Win32 " folder and select the following DLLs:
    • Leadtools.dll
    • Leadtools.Annotations.dll
    • Leadtools.Codecs.dll
    • Leadtools.WinForms.dll
    Click the Select button and then press the OK button 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 RasterImageViewer to the form. If you do not have RasterImageViewer in your toolbox, select Tools->Add Remove Toolbox Items from the menu. Click Browse and then select Leadtools.WinForms.DLL from "C:\Program Files\LEAD Technologies\LEADTOOLS 15\Bin\DotNet\Win32" and then click Open and then click OK.
  7. Change the following properties:
    PropertyValue
    DockFill
  8. Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code ) and add the following lines at the beginning of the file:

    [Visual Basic]

    
    Imports Leadtools
    Imports Leadtools.Annotations
    Imports Leadtools.Codecs
    Imports Leadtools.WinForms
    
    [C#]
    
    using Leadtools;
    using Leadtools.Annotations;
    using Leadtools.Codecs;
    using Leadtools.WinForms;
    
  9. Declare the following private variable:

    [Visual Basic]

    
    ' Annotation container object
    Private annContainerObj As AnnContainer
    
    [C#]
    
    // Annotation container object
    private AnnContainer annContainerObj;
    
  10. Add an event handler to the Form1 Load event and code it as follows:

    [Visual Basic]

    
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       ' intitialize a new RasterCodecs object
       RasterCodecs.Startup()
       Dim codecs As New RasterCodecs()
    
       ' load the main image into our viewer
       rasterImageViewer1.Image = codecs.Load("C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Sample1.cmp")
       RasterCodecs.Shutdown()
    
       If (Not IsNothing(RasterImageViewer1.Image)) Then
          ' initialize the AnnContainer object and associate it with rasterImageViewer1 image
          annContainerObj = New AnnContainer
          annContainerObj.Bounds = New AnnRectangle(0, 0, RasterImageViewer1.ImageSize.Width, RasterImageViewer1.ImageSize.Height, AnnUnit.Pixel)
          annContainerObj.Name = "Container"
          annContainerObj.Visible = True
          annContainerObj.UnitConverter = New AnnUnitConverter(96, 96)
          ' create Annotation Note Object and add it to the container
          annContainerObj.Objects.Add(CreateAnnNoteObject(New AnnRectangle(annContainerObj.Bounds.Right / 2, annContainerObj.Bounds.Bottom / 2, (annContainerObj.Bounds.Right / 4) - 1, (annContainerObj.Bounds.Bottom / 4) - 1)))
       End If
    End Sub   
    
    [C#]
    
    private void Form1_Load(object sender, System.EventArgs e)
    {
       // intitialize a new RasterCodecs object
       RasterCodecs.Startup();
       RasterCodecs codecs = new RasterCodecs();
    
       // load the main image into our viewer
       rasterImageViewer1.Image = codecs.Load(@"C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Sample1.cmp");
       RasterCodecs.Shutdown();
       
       if(rasterImageViewer1.Image != null)
       {
          // initialize the AnnContainer object and associate it with rasterImageViewer1 image
          annContainerObj = new AnnContainer();
          annContainerObj.Bounds = new AnnRectangle(0, 0, rasterImageViewer1.ImageSize.Width, rasterImageViewer1.ImageSize.Height, AnnUnit.Pixel);
          annContainerObj.Name = "Container";
          annContainerObj.Visible = true;
          annContainerObj.UnitConverter = new AnnUnitConverter(96, 96);
          // create Annotation Note Object and add it to the container
          annContainerObj.Objects.Add(CreateAnnNoteObject(new AnnRectangle(annContainerObj.Bounds.Right/2, annContainerObj.Bounds.Bottom/2, (annContainerObj.Bounds.Right/4) - 1, (annContainerObj.Bounds.Bottom/4) - 1)));
       }
    }
    
  11. Add an event handler to the rasterImageViewer1 TransformChanged event and code it as follows:

    [Visual Basic]

    
    Private Sub RasterImageViewer1_TransformChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RasterImageViewer1.TransformChanged
       If (Not IsNothing(annContainerObj)) Then
          annContainerObj.Transform = RasterImageViewer1.Transform.Clone()
       End If
    End Sub
    
    
    [C#]
    
    private void rasterImageViewer1_TransformChanged(object sender, System.EventArgs e)
    {
       if(annContainerObj != null)
          annContainerObj.Transform = rasterImageViewer1.Transform.Clone();
    }
    
  12. Add an event handler to the rasterImageViewer1 PostImagePaint event and code it as follows:

    [Visual Basic]

    
    Private Sub RasterImageViewer1_PostImagePaint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles RasterImageViewer1.PostImagePaint
       If (Not IsNothing(annContainerObj)) Then
          annContainerObj.Draw(e.Graphics)
       End If
    End Sub   
    
    [C#]
    
    private void rasterImageViewer1_PostImagePaint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
       if(annContainerObj != null)
          annContainerObj.Draw(e.Graphics);
    } 
    
  13. Add the CreateAnnNoteObject function code to class Form1:

    [Visual Basic]

    
    Private Function CreateAnnNoteObject(ByVal boundingRect As AnnRectangle) As AnnObject
       Dim annNoteObj As AnnNoteObject = New AnnNoteObject
       annNoteObj.Text = "This is my Text"
       annNoteObj.TextColor = Color.FromArgb(255, 0, 0)
       annNoteObj.Pen = New AnnPen(Color.Red, New AnnLength(3))
       annNoteObj.Brush = New AnnSolidBrush(Color.Yellow)
       annNoteObj.Font = New AnnFont(New FontFamily("Arial"), New AnnLength(14), FontStyle.Bold)
       annNoteObj.Hyperlink = "Notepad.exe"
       annNoteObj.Bounds = boundingRect
       Return annNoteObj
    End Function 
    
    [C#]
    
    private AnnObject CreateAnnNoteObject( AnnRectangle boundingRect)
    {
       AnnNoteObject annNoteObj = new AnnNoteObject();
       annNoteObj.Text = "This is my Text";
       annNoteObj.TextColor = Color.FromArgb(255, 0, 0);
       annNoteObj.Pen = new AnnPen(Color.Red , new AnnLength(3));
       annNoteObj.Brush = new AnnSolidBrush(Color.Yellow);
       annNoteObj.Font = new AnnFont(new FontFamily("Arial"), new AnnLength(14), FontStyle.Bold);
       annNoteObj.Hyperlink = "Notepad.exe";
       annNoteObj.Bounds = boundingRect;
       return annNoteObj;
    }
    
  14. Build, and Run the program to test it.