Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleLet the user add and remove dots (or potentially other annotation) to a map
DescriptionThis example shows how to let the user add and remove dots (or potentially other annotation) to a map in Visual Basic 6.
Keywordsmap, annotate, dot
CategoriesGraphics
 
The program stores dot locations in the collections DotX and DotY.

When the user clicks on the form, the MouseUp event handler calls the FindDot function to see if there is a dot at that location. If there is a dot there, the program removes it. Otherwise the program adds a new dot.

Function FindDot loops through the DotX and DotY collections checking whether the point clicked lies within the dot radius distance of each dot's center.

 
' The locations of the dots.
Private DotX As New Collection
Private DotY As New Collection

' Make a new dot if there isn't one already here.
Private Sub picMap_MouseUp(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
Dim dot_index As Integer

    dot_index = FindDot(X, Y)
    If dot_index < 0 Then
        ' Make a new dot.
        DotX.Add X
        DotY.Add Y
    Else
        ' Remove the existing dot.
        DotX.Remove dot_index
        DotY.Remove dot_index
    End If

    ' Redraw the map.
    picMap.Refresh
End Sub

' Find the dot at this location. Return its index
' or -1 if there is no dot here.
Private Function FindDot(ByVal X As Single, ByVal Y As _
    Single) As Integer
Dim i As Integer
Dim dx As Single
Dim dy As Single

    For i = 1 To DotX.Count
        ' See how far apart the dot and point are.
        dx = X - DotX(i)
        dy = Y - DotY(i)
        If dx * dx + dy * dy < DOT_R2 Then
            ' We found it.
            FindDot = i
            Exit Function
        End If
    Next i
    FindDot = -1
End Function
 
When the form redraws, the Paint event handler draws the dots.
 
' Draw the dots on the map background.
Private Sub picMap_Paint()
Dim i As Integer

    picMap.Cls
    For i = 1 To DotX.Count
        picMap.Circle (DotX(i), DotY(i)), DOT_R
    Next i
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated