I have developed a custom dockable window with textboxes, comboboxes and a button for use in ArcMap. After the user clicks on the button in the dockable window a function is invoked. After the function has finished, the focus is still on the dockable window. That’s why the user has to click into the map window, to set the focus to the ArcMap map window.

Is it possible to set the focus to the ArcMap map window programmatically?

Thus, the user could immediately use keyboard shortcuts to navigate or edit the map and does not have to click into the map before. I would implement such a functionality into the function invoked by the button in the dockable window.

Until now I haven’t found any ArcObjects interface or property which does the job. And I have no idea how I could get the handle of the ArcMap map window.

1 Answer 1


A quick and dirty fix using the Windows API:

private void button1_Click(object sender, EventArgs e)
    var app = (IApplication)this.Hook;
    var mxd = (IMxDocument)app.Document;

// Sets the keyboard focus to the specified window.
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr SetFocus(IntPtr hWnd);

A more complete solution would be to handle the Escape key within your dockable window and set the focus back to the map window then. Pressing Escape when the focus is on the table of contents, for example, sets the focus back to the map (see Keyboard shortcuts in ArcMap).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.