Marker Mouse Click Events with GMap.NET.WindowsForms

Dec 18, 2009 at 4:36 PM

Hi guys,

I am using WindowsForms in, is it possible to fire off an event when a user clicks on a marker?

I made a custom marker with the following code...

Imports GMap.NET.WindowsForms
Imports System.Drawing
Namespace GMap.NET.WindowsForms.Markers
    Public Class GMapMarkerRect
        Inherits GMapMarker
        Public Pen As Pen
        Public Sub New(ByVal p As Global.GMap.NET.PointLatLng)
            Pen = New Pen(Brushes.Red, 5)
            Size = New Size(55, 55)
        End Sub

        Public Overrides Sub OnRender(ByVal g As System.Drawing.Graphics)
            If IsMouseOver = True Then
                g.DrawRectangle(Pens.Blue, New System.Drawing.Rectangle(LocalPosition.X - Size.Width / 2, LocalPosition.Y - Size.Height / 2, Size.Width, Size.Height))
                g.DrawRectangle(Pens.Red, New System.Drawing.Rectangle(LocalPosition.X - Size.Width / 2, LocalPosition.Y - Size.Height / 2, Size.Width, Size.Height))
            End If
        End Sub
    End Class
End Namespace
any help would be great...
Dec 18, 2009 at 7:43 PM

it should work already

Dec 28, 2009 at 6:26 PM

How so, i have nowhere to specify the event.

Dec 31, 2009 at 4:22 PM

MainMap.OnMouseClick += ...

Jan 19, 2010 at 6:21 PM

Hi Radioman and all!

For the past couple of days I've been doing a test integration of into a Windows mobile 6 application written in 

I too am also stuck trying to get marker click events to occur.  I've made sure all markers have a .size value set but the events aren't occuring.

I don't entirely understand what you mean by "MainMap.OnMouseClick +=" ? 

Here's a working bare-bones copy of my code:

Public Class Form1

    Private WithEvents gm As New GMapControl
    Private gmo As New GMap.NET.WindowsForms.GMapOverlay(gm, "pins")

    Private Sub gm_OnMarkerClick(ByVal item As GMap.NET.WindowsForms.GMapMarker) Handles gm.OnMarkerClick
        ' This event never happens...
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim iMenuHeight As Integer = 26

        gm.Parent = Me
        gm.Top = 0
        gm.Width = Screen.PrimaryScreen.WorkingArea.Width
        gm.Height = Screen.PrimaryScreen.WorkingArea.Height - iMenuHeight
        gm.MapType = GMap.NET.MapType.GoogleMap
        gm.CurrentPosition = New GMap.NET.PointLatLng(52.059457, 1.155624)
        gm.MinZoom = 5
        gm.MaxZoom = 19
        gm.Zoom = 8
        gm.MarkersEnabled = True
        gm.Visible = True

    End Sub

    Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
        gm = Nothing

    End Sub

    Private Sub LoadMarkers()
        Dim p As GMap.NET.PointLatLng
        Dim m As GMap.NET.WindowsForms.GMapMarker

        ' Test marker
        p = New GMap.NET.PointLatLng(52.059457, 1.155624)
        m = New GMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(p)
        m.Visible = True
        m.Size = New System.Drawing.Size(100, 100)
        m.ToolTipText = "A marker"
        m.TooltipMode = GMap.NET.WindowsForms.MarkerTooltipMode.Never

    End Sub
End Class
Any help would be greatly appreciated.
Jan 19, 2010 at 6:33 PM

i mean MainMap.OnMarkerClick += new MarkerClick(MainMap_OnMarkerClick);

..but that for mobile is disabled, be welcome to enable it ;}

Jan 19, 2010 at 7:25 PM

Thanks for the quick reply: That explains it then! 

I also tried the following when the Click event fires:

For Each m As GMap.NET.WindowsForms.GMapMarker In gmo.Markers
            If m.IsMouseOver = True Then
                MsgBox("MouseOver " & m.ToolTipText)
            End If
But this doesn't seem to work either?  Am I doing something wrong?
Jan 19, 2010 at 8:27 PM
Edited Jan 20, 2010 at 11:13 AM

Maybe related to this "problem"(?):  When I tap on the map I'm always returned the same 'CurrentPosition' details  i.e.: 

MsgBox(gm.CurrentPosition.Lat & "," & gm.CurrentPosition.Lng)

(I'm always returned a the same value!)