AnnMouseDown example for Visual Basic
'Please note the following:
'LEADRasterView1 refers to a LEADRasterView control
'Global declarations
Private WithEvents RasterAnn As LEADRasterAnnotation
Private RasterAnnToolbar As LEADRasterAnnToolBar
'In the Form_Load method:
Set RasterAnn = New LEADRasterAnnotation
Set RasterAnnToolbar = New LEADRasterAnnToolBar
RasterAnn.AnnParentRasterView = LEADRasterView1
'This example shows
'1.
'How to create a custom annotation (circle inside a square)
'Set the AnnTool property to ANN_TOOL_USER_FIRST to see how this works
'2.
'How to restrict the rectangle annotation to be a square
'Set AnnTool property to ANN_TOOL_RECTANGLE to see how this works
'Global declarations
Dim hRectObject As Long
Dim hEllipseObject As Long
Dim x0 As Long
Dim y0 As Long
Private Sub RasterAnn_OnAnnMouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Long, ByVal y As Long)
x0 = x
y0 = y
Select Case RasterAnn.AnnTool
Case ANN_TOOL_USER_FIRST
' create the objects
RasterAnn.AnnSetSelected RasterAnn.AnnContainer, False, True
'Add an undo node to undo the creation of these objects.
RasterAnn.AnnAddUndoNode
RasterAnn.AnnCreate ANN_OBJECT_RECT, True, True
hRectObject = RasterAnn.AnnObject
RasterAnn.AnnCreate ANN_OBJECT_ELLIPSE, True, True
hEllipseObject = RasterAnn.AnnObject
' set the automation defaults to the objects newly created
RasterAnn.AnnSetAutoDefaults hRectObject, 0
RasterAnn.AnnSetAutoDefaults hEllipseObject, 0
' start defining them from the x, y coordinate
RasterAnn.AnnDefine hRectObject, x, y, ANN_DEFINE_BEGINSET
RasterAnn.AnnDefine hEllipseObject, x, y, ANN_DEFINE_BEGINSET
End Select
End Sub
Private Sub RasterAnn_OnAnnMouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Long, ByVal y As Long)
If Button = 1 Then
Select Case RasterAnn.AnnTool
Case ANN_TOOL_USER_FIRST
' update the objects from the x, y coordinate
RasterAnn.AnnDefine hRectObject, x, y, ANN_DEFINE_UPDATE
RasterAnn.AnnDefine hEllipseObject, x, y, ANN_DEFINE_UPDATE
Case ANN_TOOL_RECT
AdjustMousePos Shift, x, y
End Select
End If
End Sub
Private Sub RasterAnn_OnAnnMouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Long, ByVal y As Long)
Select Case RasterAnn.AnnTool
Case ANN_TOOL_USER_FIRST
RasterAnn.AnnDefine hRectObject, x, y, ANN_DEFINE_END
RasterAnn.AnnDefine hEllipseObject, x, y, ANN_DEFINE_END
RasterAnn.AnnSetSelected hRectObject, True, False
RasterAnn.AnnSetSelected hEllipseObject, True, False
RasterAnn.AnnGroup RasterAnn.AnnContainer, ANN_FLAG_RECURSE + ANN_FLAG_SELECTED, ""
hEllipseObject = 0
hRectObject = 0
Case ANN_TOOL_RECT
AdjustMousePos Shift, x, y
End Select
End Sub
Private Sub AdjustMousePos(ByVal Shift As Integer, ByVal x As Long, ByVal y As Long)
Dim dx As Integer
Dim dy As Integer
If Shift = 1 Then
' if shift key is down, force the creation of squares
dx = Abs(x - x0)
dy = Abs(y - y0)
If (dx > dy) Then
' adjust y to be as far from y0 as x is from x0
If y > y0 Then y = y0 + dx Else y = y0 - dx
Else
' adjust x to be as far from x0 as y is from y0
If x > x0 Then x = x0 + dy Else x = x0 - dy
End If
' set the mouse cursor and update its position
RasterAnn.SetMousePos x, y, False
End If
End Sub