As the title says, there seems to be a bug in WinformsMap’s MouseMove event. The event is fired from one to thousands of times per second, even though the mouse pointer is NOT moving at all.
These are the basic steps:
1. Create form with a WinformsMap object (“map”) and a Label (“status”)
2. Set a handler for the map.MouseMove event
3. In the event handler, increase a global integer counter and set the “status” label to this counter value.
4. Run program and let mouse pointer come to rest inside the WinformsMap object.
5. The “status” label now increases by one every second.
When the attached project is run, this behavior can be observed.
The project also includes the option to open a secondary form. The MouseMove event handler in the main form will then call a method in this secondary form. This method will set the text of a Label and a GroupBox to an integer counter value, which is increased each time the method is called. In this case, none of the counter values (neither in main form and secondary form) SEEMS to increase. However, when the mouse pointer is moved outside the WinformsMap object, the counters increase by several thousands.
To complicate matters still: If the method in the secondary form sets the text of ONLY the Label (NOT the GroupBox), then the rate of fired events is back at once per second.
Does anyone have an idea what is going on?!
We need to resolve this problem, because in our application we are using the world map coordinates (obtained in the MouseMove event) to show relevant information in a secondary form for the current pointer position)
(PS: I am using Desptop Edition 8.0.0.351)
001_RTR_TEST.zip (9.51 KB)
MouseMove event fires thousands of times even though pointer is not moved
Hi Rolf,
Thanks for your sample, that reproduced the issue succeed.
But I think that’s not a MapSuite issue, it should be an issue from winform, because we handle the MouseMove event just like a common control of winform.
You can test that follow this:
1. Use a panel instead of our winformMap, bind panel1_MouseMove instead of map_MouseMove.
2. Other code still use your test code, then you can found, before the 2nd form is opened, everything goes well. After you 2nd form is opened, the count also increase very fast, everything is the same like your test result.
My suggestion is, maybe you can add some logic in map_MouseMove event to compare currently coordinate and pervious coordinate. If they are different, then you can shows that in the 2nd form.
string previousLocation;
private void map_MouseMove(object sender, MouseEventArgs e)
{
if (previousLocation != string.Empty && previousLocation != e.Location.ToString())
{
previousLocation = e.Location.ToString();
FireCount1++;
status.Text = FireCount1.ToString();
if (secfrm != null)
secfrm.DoSomethingHere();
}
}
Wish that’s helpful.
Regards,
Don
Thanks Don, that seems to be a easy fix.
Sorry for pointing my finger at ThinkGeo, when Microsoft is to blame ;-)
Rolf,
Great to hear Don’s suggestion works, if any other questions, don’t hesitate to let us know.
Thanks,
Troy