您的位置:首页 > 编程语言 > C#

C#调用API 实现窗体总在最上

2009-06-16 17:28 627 查看
class Win32
{
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern bool SetWindowPos(
int hWnd, // window handle
int hWndInsertAfter, // placement-order handle
int X, // horizontal position
int Y, // vertical position
int cx, // width
int cy, // height
uint uFlags); // window positioning flags
public const int HWND_BOTTOM = 0x1;
public const uint SWP_NOSIZE = 0x1;
public const uint SWP_NOMOVE = 0x2;
public const uint SWP_SHOWWINDOW = 0x40;
}

private void ShoveToBackground()
{
Win32.SetWindowPos((int)this.Handle, -1, this.Location.X, this.Location.Y, this.Size.Width, this.Size.Height, 1);

//Win32.SetWindowPos(
// (int)this.Handle,
// (int),
// 0, 0, 0, 0,
// Win32.SWP_NOMOVE | Win32.SWP_NOSIZE | Win32.HWND_BOTTOM);
}

private void Bar_Activated(object sender, EventArgs e)
{
//总在最上
ShoveToBackground();
}
private void Bar_Leave(object sender, EventArgs e)
{
//总在最上
ShoveToBackground();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: