码迷,mamicode.com
首页 > 其他好文 > 详细

窗口置顶

时间:2018-08-29 14:29:24      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:win   ati   flag   打开   dllimport   ntp   port   代码   ext   

调用exe置顶用topmost=true;

exe启动之后的界面再置顶用一些代码:
[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 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);


这样,新打开的窗体就是置顶了

窗口置顶

标签:win   ati   flag   打开   dllimport   ntp   port   代码   ext   

原文地址:https://www.cnblogs.com/aijiao/p/9552534.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!