c#点击窗体右上角关闭窗口图标时,最小化窗体,但窗体不能关闭了,自己设置的退出也是最小化了

如题所述

重写窗体的OnClosing事件
protected override void OnClosing(CancelEventArgs e)
{
this.WindowState = FormWindowState.Minimized;
e.Cancel = true;
}追问

OnClosing事件怎么重写啊?新手 学习中
private void M_main_FormClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
this.Hide();
this.ShowInTaskbar = false;
this.notifyIcon1.Visible = true; //窗体按close 最小化
//Application.Exit();
}

追答

直接把我这段代码copy到你的程序代码作为一个方法就OK,
override就相当于已经把窗体的OnClosing事件重写,
而你需在关闭事件做的那些操作,就写在重写的方法体里面

追问

在程序里 , 就是没有触发啊。

追答

把FormClosing事件去掉再试试

温馨提示:内容为网友见解,仅供参考
第1个回答  2012-05-28
新手 想不出来要怎么弄 只能帮你顶下了
相似回答