C# winfrom中如何隐藏标题栏中的 关闭按钮图标?
程序中需要把关闭按钮图标给隐藏了只留下最大化和最小化哪位大侠帮小弟解决一下这个问题感谢不尽谢谢!!!...
程序中需要把关闭按钮图标给隐藏了 只留下最大化 和 最小化 哪位大侠帮小弟解决一下这个问题 感谢不尽 谢谢!!!
展开
1个回答
展开全部
双击Form_Closing事件,然后直接写以下代码,使得窗体无法关闭:private
void
Form_FormClosing(object
sender,
FormClosingEventArgs
e)
{
e.Cancel
=
true;
} C#中可没有直接屏蔽关闭按钮的方法,你硬要这样也可以:[System.Runtime.InteropServices.DllImport("user32.dll")]
static
extern
IntPtr
GetSystemMenu(IntPtr
hWnd,
bool
bRevert);
[System.Runtime.InteropServices.DllImport("user32.dll")]
static
extern
int
GetMenuItemCount(IntPtr
hMenu);
[System.Runtime.InteropServices.DllImport("user32.dll")]
static
extern
bool
DrawMenuBar(IntPtr
hWnd);
[System.Runtime.InteropServices.DllImport("user32.dll")]
static
extern
bool
RemoveMenu(IntPtr
hMenu,
uint
uPosition,
uint
uFlags);
protected
override
void
OnLoad(EventArgs
e)
{
base.OnLoad
(e);
const
Int32
MF_BYPOSITION
=
0x400;
const
Int32
MF_REMOVE
=
0x1000;
IntPtr
menu
=
GetSystemMenu(this.Handle,
false);
int
menuCount
=
GetMenuItemCount(menu);
if
(menuCount
>
1)
{
//删除菜单的「关闭」和分隔符
RemoveMenu(menu,
(uint)
(menuCount
-
1),
MF_BYPOSITION
|
MF_REMOVE);
RemoveMenu(menu,
(uint)
(menuCount
-
2),
MF_BYPOSITION
|
MF_REMOVE);
DrawMenuBar(this.Handle);
}
void
Form_FormClosing(object
sender,
FormClosingEventArgs
e)
{
e.Cancel
=
true;
} C#中可没有直接屏蔽关闭按钮的方法,你硬要这样也可以:[System.Runtime.InteropServices.DllImport("user32.dll")]
static
extern
IntPtr
GetSystemMenu(IntPtr
hWnd,
bool
bRevert);
[System.Runtime.InteropServices.DllImport("user32.dll")]
static
extern
int
GetMenuItemCount(IntPtr
hMenu);
[System.Runtime.InteropServices.DllImport("user32.dll")]
static
extern
bool
DrawMenuBar(IntPtr
hWnd);
[System.Runtime.InteropServices.DllImport("user32.dll")]
static
extern
bool
RemoveMenu(IntPtr
hMenu,
uint
uPosition,
uint
uFlags);
protected
override
void
OnLoad(EventArgs
e)
{
base.OnLoad
(e);
const
Int32
MF_BYPOSITION
=
0x400;
const
Int32
MF_REMOVE
=
0x1000;
IntPtr
menu
=
GetSystemMenu(this.Handle,
false);
int
menuCount
=
GetMenuItemCount(menu);
if
(menuCount
>
1)
{
//删除菜单的「关闭」和分隔符
RemoveMenu(menu,
(uint)
(menuCount
-
1),
MF_BYPOSITION
|
MF_REMOVE);
RemoveMenu(menu,
(uint)
(menuCount
-
2),
MF_BYPOSITION
|
MF_REMOVE);
DrawMenuBar(this.Handle);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询