Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

Now the question: 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.

Thank you

share|improve this question
up vote 5 down vote accepted

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).

share|improve this answer
Hey blah238, that's exactly what i was looking for. It works great. Thank you for answer. – Saleika Apr 11 '13 at 11:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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