c#中借助API函数使窗口置顶
2009-01-16 17:00
267 查看
由于以前做一个小程序,想把窗口置顶,其实这个技术已经不是难题了,以前在VB中也是借助于API函数。但在C#中没想用API函数,至今没找到好办法,最后还得借助于API函数。
片断代如下:
[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);
这样,新打开的窗体就是置顶了。呵
片断代如下:
[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#SetWindowPos窗口置顶
- C#(winform)设置窗口置顶
- c# winform窗口一直置顶显示在桌面最上方的方法
- C# SetWindowPos窗口置顶使用说明
- C#调用windows的API函数实现将不活动窗口置为活动窗口,并置前显示
- C# 窗口置顶
- C#API函数介绍一(打开程序和显示窗口)
- C# SetWindowPos窗口置顶使用说明
- [置顶] C# 窗口间传值
- C# SetWindowPos窗口置顶使用说明
- c#调用API函数拖动无标题窗口及控件
- 调用API函数,在窗口非客户区绘图(C# GDI+编程)
- 分辨率类[置顶] c# winform窗口自适应各种分辨率类
- c# winform窗口一直置顶显示在桌面最上方或最底层的方法
- C#去掉窗口最小化时左下角的窗口
- C# winfrom listview 多窗口调用
- [置顶] Spring boot和Mybatis整合+Mysql+jsp页面跳转问题(借助FreeMarker)
- [置顶] C#中Socket服务端代码分享
- C#调试中,在VS的输出窗口或即时窗口显示消息
- C#中通过父窗口调用子窗口的问题