Search code examples
c#winformsgmap.net

OnMarkerClick events fires multiple times


I try to popup a messagebox when the marker was left-clicked. When the marker was clicked, the event was fired, the popup was showing, but it fires multiple times (2 times).

This is my code

private void gmap_mainMap_OnMarkerClick(GMapMarker item, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Left && item.IsMouseOver){
        MessageBox.Show("Marker clicked", "Information");
    }
}

Anyone have idea why the event keeps firing multiple times? Thanks!


Solution

  • just to make sure, you can do this:

    private bool MarkerWasClicked = false;
    
    private void gmap_mainMap_OnMarkerClick(GMapMarker item, MouseEventArgs e)
    {
        MarkerWasClicked = false;
    
        if (MarkerWasClicked == false){
            if (e.Button == System.Windows.Forms.MouseButtons.Left && item.IsMouseOver){
                MessageBox.Show("Marker clicked", "Information");
                MarkerWasClicked = true;
            }
        }
    }