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;


返回导读目录,阅读更多随笔



分割线,以下为博客签名:

软件臭虫情未了
  • 编码一分钟
  • 测试十年功


随笔如有错误或不恰当之处、为希望不误导他人,望大侠们给予批评指正。

原文地址:https://www.cnblogs.com/08shiyan/p/2001326.html