ThinkGeo.com    |     Documentation    |     Premium Support

MapKeyDown Event not Firing

Hi,

With the latest beta 089 the following event no longer fires. This was working in the latest stable release.

WinMap.ExtentOverlay.MapKeyDown += ExtentOverlay_MapKeyDown;

It works for me with both 089 and the latest 091. Can you clean up the bin/obj and have another try? If still have issues, can you send over a demo project to us?

Hi Ben,

I can get the event to fire in a much more simple project, so there must be something else in my production project that is inhibiting that event.

I have noticed something. I have panels around my map and for some reason even if I click the map, the focus stays within the panels. What doesn’t make sense to me is that the MapMouseClick still fires when I click the map. Any ideas how to get the map to keep focus once clicked?

Also, this code does nothing in the simple project I made. It’s supposed to pan down.

        if (e.InteractionArguments.Key == System.Windows.Input.Key.Down)
        {
            WinMap.PanByDegreesAndScreenDistanceAsync(180f, 200);
            WinMap.RefreshAsync();
        }

An update for you. If I tear off the docked panels, the map again receives focus and it starts responding to the MapKeyDown event. These same panels are in my v10 project and there is no issue. The only difference there is that the map control is embedded on the form in my v10 project and here I programmatically add the map to the control at runtime (being sure to Bring To Front the map control).

Here’s some images. This first one has the panel attached and it does not respond to the event.

This one with the panel detached does respond even though the panel is floating over the map. Notice how the navigation control appears to be focused in this image…

hi @Damian_Hite,

Could you try to set Focusable property of MapView to true?

I created a sample to demonstrate this issue. The left and right panels were designed to match your scenario, so the buttons, checkboxes, and textboxes were not working.

As you can see from the gif, if the Map’s Focusable is false, MapKeyDown event doesn’t fire even I click the map or click the button “Set Map Focus”. If the Map’s Focusable is true, MapKeyDown enent can fire properly.

MapKeyFocusExample.zip (12.0 KB)

Regards,
Leo

hi @Damian_Hite,

Could you try to set Focusable property of MapView to true?

I created a sample to demonstrate this issue. The left and right panels were designed to match your scenario, so the buttons, checkboxes, and textboxes were not working.

As you can see from the gif, if the Map’s Focusable is false, MapKeyDown event doesn’t fire even I click the map or click the button “Set Map Focus”. If the Map’s Focusable is true, MapKeyDown event can fire properly.

MapKeyFocusExample.zip (12.0 KB)

Regards,
Leo

Hi Leo,

In WinForms, there is no such property. Here’s the options. I have tried setting MapFocusMode to MouseEnterFocus, but that appears to be the default in the first place. Note that the CanFocus value does show False…

image

hi @Damian_Hite,

Just realized that you’re using WinForms. You could use the code blow in mapView1_MapMouseDown event to focus on the map. You need to add PresentationCore and WindowsBase to your project refrences.

mapView1.MapTools.PanZoomBar.CurrentMap.Focusable = true;
mapView1.MapTools.PanZoomBar.CurrentMap.Focus();

In the sample below, I clicked the map or clicked the button “Focus On Map”, the MapKeyDown event can fire properly.

WinFormsMapKeyDownIssue.zip (14.3 KB)

Regards,
Leo

It works! Thanks Leo.

Glad to hear it’s working! Happy to assist—your prompt feedback was very helpful in troubleshooting.

Regards,
Leo