Creating and Using Annotations (Access 2.0)
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.
1. Start with the project that you created in Loading and Displaying an Image.
2. Using the control wizard, create a list box with the following entries for selecting annotation tools. (Note that hot spots and buttons are not used, because Access 2.0 does not support annotation events.)
Selection
Line
Rectangle
Ellipse
Polyline
Polygon
Pointer
Freehand
Highlight
Redaction
Text
Note
Stamp
Audio
3. Name the list box control AnnTool and code its click event as follows:
Sub AnnTool_Click ()
Select Case AnnTool.Value
Case "Selection"
Me![LEAD1].Object.AnnTool = ANNTOOL_SELECT
Case "Line"
Me![LEAD1].Object.AnnTool = ANNTOOL_LINE
Case "Rectangle"
Me![LEAD1].Object.AnnTool = ANNTOOL_RECT
Case "Ellipse"
Me![LEAD1].Object.AnnTool = ANNTOOL_ELLIPSE
Case "Polyline"
Me![LEAD1].Object.AnnTool = ANNTOOL_POLYLINE
Case "Polygon"
Me![LEAD1].Object.AnnTool = ANNTOOL_POLYGON
Case "Pointer"
Me![LEAD1].Object.AnnTool = ANNTOOL_POINTER
Case "Freehand"
Me![LEAD1].Object.AnnTool = ANNTOOL_FREEHAND
Case "Highlight"
Me![LEAD1].Object.AnnTool = ANNTOOL_HILITE
Case "Redaction"
Me![LEAD1].Object.AnnTool = ANNTOOL_REDACT
Case "Text"
Me![LEAD1].Object.AnnTool = ANNTOOL_TEXT
Case "Note"
Me![LEAD1].Object.AnnTool = ANNTOOL_NOTE
Case "Stamp"
Me![LEAD1].Object.AnnTool = ANNTOOL_STAMP
Case "Audio"
Me![LEAD1].Object.AnnTool = ANNTOOL_AUDIO
Case Else
MsgBox "Invalid Selection"
End Select
End Sub
4. 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 |
5. 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.
Sub AnnToggle_Click ()
'Use the button to toggle between design mode and run mode
If AnnToggle.Caption = "Start" Then
Me![LEAD1].Object.AnnUserMode = ANNUSERMODE_DESIGN
'Make run mode the next thing.
AnnToggle.Caption = "Run Mode"
ElseIf AnnToggle.Caption = "Design Mode" Then
Me![LEAD1].Object.AnnUserMode = ANNUSERMODE_DESIGN
'Make run mode the next thing.
AnnToggle.Caption = "Run Mode"
Else 'The button takes us to run mode
Me![LEAD1].Object.AnnUserMode = ANNUSERMODE_RUN
'Make design mode the next thing.
AnnToggle.Caption = "Design Mode"
End If
End Sub
6. Code the IOToggle control's Click procedure as follows:
Sub IOToggle_Click ()
'Declare local variable
Dim nRet As Integer
'Disable errors so that we can trap our own.
Me![LEAD1].Object.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 Me![LEAD1].Object.AnnContainer = 0 Then Exit Sub
'Save the selected annotations.
nRet = Me![LEAD1].Object.AnnSave("c:\lead\images\tmp.ann", ANNFMT_NATIVE, True)
If nRet = 0 Then
'Make loading the next thing.
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
Me![LEAD1].Object.AnnUserMode = ANNUSERMODE_DESIGN
'Load the annotations.
nRet = Me![LEAD1].Object.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
7. 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.)
Sub ClipboardToggle_Click ()
'Declare local variable
Dim nRet As Integer
'Disable errors so that we can trap our own.
Me![LEAD1].Object.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 Me![LEAD1].Object.AnnContainer = 0 Then Exit Sub
'Copy the selected annotations to the clipboard.
nRet = Me![LEAD1].Object.AnnCopy(ANNFMT_NATIVE, True, 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
Me![LEAD1].Object.AnnUserMode = ANNUSERMODE_DESIGN
'Paste the annotations
If Me![LEAD1].Object.AnnPasteReady Then
Me![LEAD1].Object.AnnPaste
ClipboardToggle.Caption = "Copy"
Else
MsgBox "No annotations to paste"
End If
End If
End Sub
8. Code the Realize control's Click procedure (which renders the annotation objects to the bitmap) as follows:
Sub Realize_Click ()
Me![LEAD1].Object.AnnRealize False
Me![LEAD1].Object.ForceRepaint
MsgBox "Annotations are now rendered to the bitmap"
End Sub
9. Run your program to test it.