关于C#关闭窗口事件

来源:百度知道 编辑:UC知道 时间:2024/05/28 06:09:02
本人想做一个界面 那个界面 当你点击上面那个 关闭 X 键时 关闭不掉
一定要选择自己创建的一个 退出按钮而退出 `
明白意思的请把代码发送给我 谢谢 不明白的 误发

做个开关
bool a = fasle;
在FORMCLOSING事件中添加如下代码:
if (a)
{
e.Cancel = true;
}
退出按钮
a = true;

在FORMCLOSING事件中添加如下代码:
this.WindowState = FormWindowState.Minimized; // 最小化到任务栏
e.Cancel = true; // 拦截窗体关闭消息

你可以把页面上那栏不做显示 , 不就看不到X了

我想你要的是:
#region 窗口关闭事件
protected override void OnFormClosing(FormClosingEventArgs e)
{
try
{
if (MessageBox.Show("\r\n你确认要退出该程序吗?", "标题字符串", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
try
{

base.OnFormClosing(e);

}
catch (Exception r)
{
MessageBox.Show(r.Mess