首页 > 编程知识 正文

WinForm SetWindowPos窗口置顶使用说明,enscape窗口置顶怎么使用

时间:2023-05-03 20:21:39 阅读:249814 作者:4128

就是有时候窗口不能够成功置顶,这时需要重新切换下标签,就可以置顶了,本文介绍C# SetWindowPos实现窗口置顶的方法:

[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);

转载于:https://www.cnblogs.com/51net/p/10983112.html

UCloud云社区jquery可不可以获取链接的内容

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。