展会信息港展会大全

C#SetWindowPos窗口置顶
来源:互联网   发布日期:2016-01-27 15:28:06   浏览:1426次  

导读:[DllImport(user32 dll, CharSet = CharSet Auto)]private static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags); ...

[DllImport("user32.dll", CharSet = CharSet.Auto)]

private static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags);

/// <summary>

/// 得到当前活动的窗口

/// </summary>

/// <returns></returns>

[DllImport("user32.dll", CharSet = CharSet.Auto)]

private static extern System.IntPtr GetForegroundWindow();

哪个窗体想要置顶,在Form_Load中加上

SetWindowPos(this.Handle, -1, 0, 0, 0, 0, 1 | 2); //最后参数也有用1 | 4

具体说明,看API函数说明

如果是用点击一个按钮后弹出新窗体,并置顶,则:

Form2 frm = new Form2();

frm.Show();

SetWindowPos(GetForegroundWindow(), -1, 0, 0, 0, 0, 1 | 2);

赞助本站

人工智能实验室

相关热词: 窗口 置顶 Window

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港