C# 窗口置顶

1、引入命名空间:

using System.Runtime.InteropServices;


2、在窗口类中加入:

[DllImport("user32.dll")]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hPos,
int x, int y, int cx, int cy, uint nflags);


3、在窗口的Load事件中加入:

置顶

IntPtr HWND_TOPMOST = new IntPtr(-1);
SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, 0x0001 | 0x0002);
 

取消置顶

IntPtr HWND_TOPMOST = new IntPtr(-2);
SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, 0x0001 | 0x0002);
posted @ 2011-07-30 09:18  jex  阅读(858)  评论(0)    收藏  举报