C#,winform中如何屏蔽右上角的X关闭按钮
展开全部
调用Windows
API试一下
[DllImport("user32.dll")]
internal
static
extern
IntPtr
GetSystemMenu(IntPtr
hwnd,bool
bRevert);
[DllImport("user32.dll")]
internal
static
extern
int
GetMenuItemCount(IntPtr
hMenu);
[DllImport("user32.dll")]
internal
static
extern
int
RemoveMenu(IntPtr
hMenu,int
uPosition,int
uFlags);
///
<summary>
///
窗体的关闭按钮失效
///
</summary>
protected
void
CloseButtonEnable(){
//
默认窗口去除关闭按钮
const
int
MF_BYPOSITION
=
0x00000400;
IntPtr
hWindow
=
this.Handle;
IntPtr
hMenu
=
GetSystemMenu(hWindow,false);
int
count
=
GetMenuItemCount(hMenu);
RemoveMenu(hMenu,count
-
1,MF_BYPOSITION);
RemoveMenu(hMenu,count
-
2,MF_BYPOSITION);
}
API试一下
[DllImport("user32.dll")]
internal
static
extern
IntPtr
GetSystemMenu(IntPtr
hwnd,bool
bRevert);
[DllImport("user32.dll")]
internal
static
extern
int
GetMenuItemCount(IntPtr
hMenu);
[DllImport("user32.dll")]
internal
static
extern
int
RemoveMenu(IntPtr
hMenu,int
uPosition,int
uFlags);
///
<summary>
///
窗体的关闭按钮失效
///
</summary>
protected
void
CloseButtonEnable(){
//
默认窗口去除关闭按钮
const
int
MF_BYPOSITION
=
0x00000400;
IntPtr
hWindow
=
this.Handle;
IntPtr
hMenu
=
GetSystemMenu(hWindow,false);
int
count
=
GetMenuItemCount(hMenu);
RemoveMenu(hMenu,count
-
1,MF_BYPOSITION);
RemoveMenu(hMenu,count
-
2,MF_BYPOSITION);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询