I have an ArcGIS 10 ArcMap add-in written in C# .NET 3.5 that implements an ESRI.ArcGIS.Desktop.AddIns.DockableWindow (which also inherits from UserControl) and an ESRI.ArcGIS.Desktop.AddIns.Tool that when clicked in the map updates the dockable window.

I'd like to bring the dockable window to the front of the Z-order in the Tool's OnMouseDown() method (when in undocked mode). Currently, if the user opens another dockable window, puts it on top of mine, and clicks with the tool, the window updates but it is not brought to the front. I am already calling IDockableWindow.Show(true) to ensure the window is visible after clicking with the tool. I have also tried UserControl.BringToFront() but it does not have any effect.

The best workaround I currently have is to call IDockableWindow.Show(false) followed by IDockableWindow.Show(true), however this not ideal as it is jarring to have the window disappear and reappear, as well as have to fully repaint which takes a substantial amount of time.

The built-in Identify window does not have this issue and is brought to the top each time the Identify tool is used, so clearly there is a way to do it.

Does anyone know of a better solution to this? Thanks!

Edit: Here is the code I ended up using to resolve this. Thanks Kirk and Petr!

public static void BringDockableWindowToFront(IDockableWindow dockableWindow, IntPtr dockableWindowControlHandle)
/// <summary>
/// Workaround for bringing a dockable window to the top of the Z order.
/// dockableWindowControlHandle is the Handle property of the UserControl implemented by the dockable window
/// </summary>
    IWindowPosition windowPos = dockableWindow as IWindowPosition;
    IntPtr parentHwnd = GetParent(dockableWindowControlHandle); // Get parent window handle
    switch (windowPos.State)
        case esriWindowState.esriWSFloating:
            IntPtr grandParentHwnd = GetParent(parentHwnd); // Get grandparent window handle
            SetActiveWindow(grandParentHwnd);  // Activate grandparent window when in floating (undocked) mode
        //case esriWindowState.esriWSMaximize: // Mode not yet implemented in ArcGIS 10, check at 10.1
        //case esriWindowState.esriWSMinimize: // Mode not yet implemented in ArcGIS 10, check at 10.1
        case esriWindowState.esriWSNormal:
            SetActiveWindow(parentHwnd); // Activate parent window when in normal (docked) mode
    SetFocus(dockableWindowControlHandle); // Set keyboard focus to the dockable window

// Retrieves a handle to the specified window's parent or owner.
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetParent(IntPtr hWnd);

// 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);

// Activates a window.
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr SetActiveWindow(IntPtr hWnd);
  • can you send/post me the sample for dockwindow add in?
    – user22852
    Oct 11, 2013 at 16:47

1 Answer 1


Try using the SetWindowPos winapi call with the hWnd of the dockable window control (or maybe it's parent or grandparent container control) with the HWND_TOP flag.

  • Thanks Kirk, I actually just tried exactly that but it had no effect. The dockable window has no parent control, but its Left and Top properties are 0, so I assume that to mean it really does have a parent window (other than the ArcMap application). I really hate that there isn't an easier way to do this than mucking about with the Windows API. Have you had any luck with this yourself?
    – blah238
    May 16, 2011 at 17:36
  • Also strange, but the IWindowPosition co-class's Left and Top properties are correct, but its Move method has no effect.
    – blah238
    May 16, 2011 at 17:48
  • 2
    Using spy++, and looking at an undocked window, I see that it's great grandparent is arcmap. So I'd figure the zorder would be set by the grandparent of the dockable window. You're right - it sure seems like there'd be an easier way. May 16, 2011 at 18:01
  • 2
    It is indeed the grandparent window. Relying on this structure is not ideal though, since it may easily break in future versions of ArcMap. ESRI should really provide some interface to do this.
    – Petr Krebs
    May 16, 2011 at 18:27
  • Thanks guys, it was a bit of a slog but I was able to get it working. Edited the question with the coded solution.
    – blah238
    May 16, 2011 at 19:42

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.