1.隐藏窗体最大化,最小化,以及关闭按钮的话,可以再窗体的属性面板设置
将ResizeMode=NoResize时,将不会显示最大化最小化,只有关闭按钮;如下图:
2最大化按钮被禁用,但是还是会显示,不能按,最小化,关闭按钮正常显示,.设置窗体属性ResizeMode="CanMinimize";
3.隐藏最大化,最小化,以及关闭按钮,周围的边框也不存在,设置窗体属性WindowStyle="None"。
4.禁用关闭按钮
重载OnClosing()函数实现--使用户无法通过点击右上角的关闭按钮来关闭窗口
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
}
//去除关闭按钮
//先在window类中声明:
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, UInt32 bRevert);
[DllImport("USER32.DLL ", CharSet = CharSet.Unicode)]
private static extern UInt32 RemoveMenu(IntPtr hMenu, UInt32 nPosition, UInt32 wFlags);
private const UInt32 SC_CLOSE = 0x0000F060;
private const UInt32 MF_BYCOMMAND = 0x00000000;
//然后,在装载事件(load)中加入:
var hwnd = new WindowInteropHelper(this).Handle;
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);