SetWindowPos (user32)
Last changed: Ozymandius257-86.25.164.114

.
Summary

C# Signature:

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, SetWindowPosFlags uFlags);

VB.NET Signature:

<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As SetWindowPosFlags) As Boolean
End Function

User-Defined Types:

SetWindowPosFlags

C# Constants:

static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
static readonly IntPtr HWND_TOP = new IntPtr(0);
static readonly IntPtr HWND_BOTTOM = new IntPtr(1);

VB.NET Constants:

Private ReadOnly HWND_BOTTOM As New IntPtr(1)
Private ReadOnly HWND_NOTOPMOST As New IntPtr(-2)
Private ReadOnly HWND_TOP As New IntPtr(0)
Private ReadOnly HWND_TOPMOST As New IntPtr(-1)

Notes:

HWND_TOP will bring a window to the front of the Z-Order only if the thread is in the foreground. Otherwise it will bring the window to the front of the thread's Z-order.

Alternative Managed API:

Use the System.Windows.Forms.Form.TopMost property.

Documentation