c# 关闭右上角的X 如何设置为退出程序
2个回答
展开全部
是FormClosing的事件,在窗体执行关闭时触发的代码,不是FormClosed,那是在窗体关闭后才触发,不过系统默认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);
///
///
窗体的关闭按钮失效
///
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);
///
///
窗体的关闭按钮失效
///
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);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询