c# winform 点右上角关闭按钮的程序中如何加入一段代码

protected override void WndProc(ref Message msg)
2{
3 const int WM_SYSCOMMAND = 0x0112;
4 const int SC_CLOSE = 0xF060;
5
6 if (msg.Msg == WM_SYSCOMMAND && ((int)msg.WParam == SC_CLOSE))
7 {
8 // 点击winform右上关闭按钮
9 // 此处加入一段代码(调用button的click事件)
10
11
12
13 return;
14 }
15 base.WndProc(ref msg);

-----------------------------------------------------------------
private void btn_mainExit_Click(object sender, EventArgs e)


xxxxxxxxxx 若干语句
Application.Exit();

-----------------------------------------------------------------

请问在上面程序的第九行,如何调用button的click事件???

我在第9行插入
btn_mainExit_Click(sender, e) 不对
不知道怎么写?

如果你的click函数中没有用到相应的按钮,直接
btn_mainExit_Click(null,null)即可,因为你们使用这2个参数。

还有
Form有个事件叫做
FormClosing
还有个FormClosed
希望对你有帮助!
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-08-11
你可以调用winfrom的FormClosed事件,效果应该是一样的吧
相似回答