[DllImport("coredll.dll", EntryPoint="GetCapture", SetLastError=true)]
private static extern IntPtr GetCapture();
[DllImport("coredll.dll", EntryPoint="SetWindowPos", SetLastError=true)]
private static extern bool SetWindowPos(
IntPtr hWnd,
IntPtr hWndInsertAfter,
int x,
int y,
int cx,
int cy,
uint uFlags);
public IntPtr GetControlHandle(Control ctl)
{
ctl.Capture = true;
IntPtr hWnd = GetCapture();
ctl.Capture = false;
return hWnd;
}
///
/// Set a form to the top most position.
///
/// The form to set topmost.
///
public bool SetWindowTopMost(Form frm)
{
return SetWindowTopMost(frm, true);
}
///
/// Set a form to the top most position.
///
/// The form to set topmost.
/// True to set the form topmost, false to set the form to no topmost.
///
public bool SetWindowTopMost(Form frm, bool bTopMost)
{
// Get the handle to the form entered.
IntPtr hWnd = GetControlHandle(frm);
IntPtr hWndInsertAfter = IntPtr.Zero;
if (bTopMost)
{
// Set the topmost flag.
hWndInsertAfter = new IntPtr(HWND_TOPMOST);
}
else
{
// Set the no topmost flag.
hWndInsertAfter = new IntPtr(HWND_NOTOPMOST);
}
return SetWindowPos(hWnd, hWndInsertAfter, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
}
No comments:
Post a Comment