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 click to draw markers on a map in Visual Basic 2005
DescriptionThis example shows how to let the user click to draw markers on a map in Visual Basic 2005.
Keywordsdrawing, map, marker, Paint, Visual Basic 2005, VB.NET
CategoriesGraphics, VB.NET
 
The program declares a generic List(Of Rectangle) to hold information about the markers.

When the user clicks on the map, the program adds a new Rectangle to the list, placing it at the location the user clicked.

The map's Paint event handler loops through the markers drawing them.

Finally the Clear Markers button empties the list of markers.

 
Private m_Markers As New List(Of Rectangle)

' Add a marker.
Private Sub picMap_MouseClick(ByVal sender As Object, ByVal _
    e As System.Windows.Forms.MouseEventArgs) Handles _
    picMap.MouseClick
    Const WID As Integer = 7
    m_Markers.Add(New Rectangle(e.X - WID \ 2, e.Y - WID \ _
        2, WID, WID))

    ' Redraw.
    picMap.Invalidate()
End Sub

' Draw the markers.
Private Sub picMap_Paint(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.PaintEventArgs) Handles _
    picMap.Paint
    For Each rect As Rectangle In m_Markers
        e.Graphics.FillEllipse(Brushes.Red, rect)
        e.Graphics.DrawEllipse(Pens.Black, rect)
    Next rect
End Sub

' Clear the markers.
Private Sub btnClearMarkers_Click(ByVal sender As _
    System.Object, ByVal e As System.EventArgs) Handles _
    btnClearMarkers.Click
    m_Markers.Clear()

    ' Redraw.
    picMap.Invalidate()
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated