标题 | 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); |
随便看 |
|
在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。