Setting a Windows form to be bottommost

This isn’t directly supported by the .NET Form class, so you have two options:

1) Use the Win32 API SetWindowPos function.

pinvoke.net shows how to declare this for use in C#:

[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 SWP_NOACTIVATE = 0x0010;

So in your code, call:

SetWindowPos(Handle, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

As you commented, this moves the form to the bottom of the z-order but doesn’t keep it there. The only workaround I can see for this is to call SetWindowPos from the Form_Load and Form_Activate events. If your application is maximized and the user is unable to move or minimise the form then you might get away with this approach, but it’s still something of a hack. Also the user might see a slight “flicker” if the form gets brought to the front of the z-order before the SetWindowPos call gets made.


2) subclass the form, override the WndProc function and intercept the WM_WINDOWPOSCHANGING Windows message, setting the SWP_NOZORDER flag (taken from this page).

Leave a Comment