用户名:
密 码: 记住
您当前的位置:首页 > 网络编程 > Net教程

C# SetWindowPos窗口置顶使用说明

时间:2015-01-29  来源:互联网  作者:佚名
复制代码 代码如下:
[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);

这样,新打开的窗体就是置顶了
来顶一下
返回首页
返回首页
推荐资讯
C#页码导航显示及算法实现代码 C#页码导航显示及算法实现代码页码导航,先看显示效果: 算法要求: 1、页数小于等于1时不
WinForm中窗体间的数据传递交互的一些方法 WinForm中窗体间的数据传递交互的一实际上过去我也写过类似的主题,这里把各种方法总结一下,内
相关文章
    无相关信息
栏目更新
栏目热门