C# 处理无边框窗体

1、右击任务栏图标显示右键菜单

[DllImport(
"user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
public static extern int GetWindowLong(HandleRef hWnd, int nIndex);

[DllImport(
"user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
public static extern IntPtr SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong);


private void ShowContextMenuStrip()
{
int WS_SYSMENU = 0x00080000; // 系统菜单
int WS_MINIMIZEBOX = 0x20000; // 最大最小化按钮

int windowLong = (GetWindowLong(new HandleRef(this, this.Handle), -16));
SetWindowLong(
new HandleRef(this, this.Handle), -16, windowLong | WS_SYSMENU | WS_MINIMIZEBOX);
}
2、设定最大Bounds 为 主显示器的WorkingArea区域 防止最大化掩盖任务栏
           this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;
posted @ 2011-03-31 17:31  把爱延续  阅读(995)  评论(0编辑  收藏  举报