private static void UpdateZOrderOfOwner(IntPtr hwndOwner) { var lastOwnedWindow = IntPtr.Zero; NativeMethods.EnumThreadWindows(NativeMethods.GetCurrentThreadId(), (hwnd, lParam) => { if (NativeMethods.GetWindow(hwnd, 4) == hwndOwner) { lastOwnedWindow = hwnd; } return(true); }, IntPtr.Zero); if (!(lastOwnedWindow != IntPtr.Zero) || !(NativeMethods.GetWindow(hwndOwner, 3) != lastOwnedWindow)) { return; } NativeMethods.SetWindowPos(hwndOwner, lastOwnedWindow, 0, 0, 0, 0, 19); }