Creating and Using Annotations (Visual Basic)

Note: This topic is for Document/Medical only.

Take the following steps to add code that demonstrates the creation and deletion, saving and loading, and copying and pasting of annotation objects. This code also demonstrates the related events. Message boxes prompt for user actions that trigger events.

1.

Start with the project that you created in Loading and Displaying an Image.

2.

Add the LEAD Raster Annotation Library to your project.

 

On the Project pull-down menu, use the References option, and select the LEAD Raster Annotation Object Library

3.

Add the following code to the general declarations section of your project

Public WithEvents RasterAnn As LEADRasterAnnotation
Public RasAnnToolbar As LEADRasterAnnToolBar

4.

Add the following code to the main form's Load procedure

  Set RasterAnn = New LEADRasterAnnotation
  Set RasAnnToolbar = New LEADRasterAnnToolBar

  'Unlock annotation support
  LEADRasterView1.Raster.UnlockSupport L_SUPPORT_DOCUMENT, L_KEY_DOCUMENT
  
  'Connect the raster annotation object to the RasterView control
  RasterAnn.AnnParentRasterView = LEADRasterView1

  'Enable left button drawing of annotations
  RasterAnn.AnnAutoDrawEnable = True
  
  'Enable right-click to display annotation menus
  RasterAnn.AnnAutoMenuEnable = True

5.

image\btncmd.gif At the top of your main form, add four command buttons and name them as follows:

 

Name

Caption

 

AnnToggle

Start

 

IOToggle

Save

 

ClipboardToggle

Copy

 

Realize

Realize

6.

Code the AnnToggle control's Click procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code.

Private Sub AnnToggle_Click()
'Use the button to toggle between design mode and run mode
If AnnToggle.Caption = "Start" Then
    RasterAnn.AnnUserMode = ANN_USERMODE_DESIGN
    RasterAnn.AnnTool = ANN_TOOL_BUTTON
    'Make run mode the next thing.
    AnnToggle.Caption = "Run Mode"
    MsgBox "In design mode now. Draw a button object."
ElseIf AnnToggle.Caption = "Design Mode" Then
    RasterAnn.AnnUserMode = ANN_USERMODE_DESIGN
    RasterAnn.AnnTool = ANN_TOOL_BUTTON
    'Make run mode the next thing.
    AnnToggle.Caption = "Run Mode"
Else 'The button takes us to run mode
    RasterAnn.AnnUserMode = ANN_USERMODE_RUN
    MsgBox "Click on your new button"
    AnnToggle.Caption = "Design Mode"
End If
End Sub

7.

Code the IOToggle control's Click procedure as follows:

Private Sub IOToggle_Click()
Dim nRet As Integer

'Disable errors so that we can trap our own.
RasterAnn.EnableMethodErrors = False
'Use the button to toggle between saving and loading annotations
If IOToggle.Caption = "Save" Then
    'Do nothing if there are no annotations.
    If RasterAnn.AnnContainer = 0 Then Exit Sub
        'Save the all annotations.
        nRet = RasterAnn.AnnSave("c:\lead\images\tmp.ann", ANN_FMT_NATIVE, False, SAVE_OVERWRITE, 0)
        If nRet = 0 Then
            IOToggle.Caption = "Load"
            MsgBox "Use the right mouse button to delete any annotations, then click Load"
        Else
            MsgBox "Error code: " + Str(nRet)
        End If
Else 'We are loading annotations
    'Make sure we are in design mode
    RasterAnn.AnnUserMode = ANN_USERMODE_DESIGN
    'Load the annotations.
   nRet = RasterAnn.AnnLoad("c:\lead\images\tmp.ann", 1)
    If nRet = 0 Then
        IOToggle.Caption = "Save"
    Else
        MsgBox "No annotations to load"
    End If
End If
End Sub

8.

Code the ClipboardToggle control's Click procedure as follows. (Note that Copy, Cut, and Paste are available as automated popup menu options. This code is for tailoring your application.)

Private Sub ClipboardToggle_Click()
Dim nRet As Integer
'Disable errors so that we can trap our own.
RasterAnn.EnableMethodErrors = False
'Use the button to toggle between copying and pasting annotations
If ClipboardToggle.Caption = "Copy" Then
    'Do nothing if there are no annotations.
    If RasterAnn.AnnContainer = 0 Then Exit Sub
    'Copy all annotations to the clipboard.
    nRet = RasterAnn.AnnCopy(ANN_FMT_NATIVE, False, True)
    If nRet = 0 Then
        'Make pasting the next thing.
        ClipboardToggle.Caption = "Paste"
        MsgBox "Use the right mouse button to delete any annotations, then click Paste"
   Else
        MsgBox "Error code: " + Str(nRet)
    End If
Else 'We are pasting annotations
    'Make sure we are in design mode
    RasterAnn.AnnUserMode = ANN_USERMODE_DESIGN
    'Paste the annotations
    If RasterAnn.AnnPasteReady Then
        nRet = RasterAnn.AnnPaste
        ClipboardToggle.Caption = "Copy"
    Else
        MsgBox "No annotations to paste"
    End If
End If
End Sub

9.

Code the Realize control's Click procedure (which renders the annotation objects to the bitmap) as follows:

Private Sub Realize_Click()
RasterAnn.AnnRealize False
LEADRasterView1.ForceRepaint
MsgBox "Annotations are now rendered to the bitmap"
End Sub

10.

Code the RasterAnn object's AnnCreate procedure as follows:

Private Sub RasterAnn_OnAnnCreate(ByVal hAnnObject As Long)
Dim hObject As Long
Dim ObjectType As AnnObjectType
' Update the tag if we need one.
Static NewTag As Integer
RasterAnn.AnnGetType hObject
ObjectType = RasterAnn.AnnType
If ObjectType = ANN_OBJECT_BUTTON Or ObjectType = ANN_OBJECT_HOTSPOT Then
    NewTag = NewTag + 1
    RasterAnn.AnnSetTag hObject, NewTag
End If
End Sub

11.

Code the RasterAnn object's AnnDrawn procedure as follows:

Private Sub RasterAnn_OnAnnDrawn(ByVal hAnnObject As Long)
RasterAnn.AnnTool = ANN_TOOL_SELECT
MsgBox "Use the right mouse button to modify this object; then click on Run Mode to test it."
End Sub

12.

Code the RasterAnn object's AnnClicked procedure as follows:

Private Sub RasterAnn_OnAnnClicked(ByVal hAnnObject As Long)
Dim lTag As Long
RasterAnn.AnnGetTag hAnnObject
lTag = RasterAnn.AnnTag
MsgBox "This is what we do for the button tagged " + Str(lTag)
End Sub

13.

Code the RasterAnn object's AnnDestroy procedure as follows:

Private Sub RasterAnn_OnAnnDestroy(ByVal hAnnObject As Long)
Dim lTag As Long
RasterAnn.AnnGetTag hAnnObject
lTag = RasterAnn.AnnTag
MsgBox "The object tagged " + Str(lTag) + " is deleted."
End Sub

14.

Run your program to test it.