表单关闭后从特定上下文运行代码?

时间:2010-09-16 18:54:32

标签: c# winforms

我希望在此处创建的表单关闭后在此上下文中运行一些代码。

Form1 Form1 = new Form1();
Form1.Show(); //<-After this closes, I want to run code from this context, using ShowDialog() is not an option

1 个答案:

答案 0 :(得分:1)

只需注册FormClosing

Form事件
void MyClosingEvent(object o, FormClosingEventArgs args)
{
}

private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
    Form1 form1 = new Form1();
    form1.FormClosing += new FormClosingEventHandler(MyClosingEvent);
    //Or if you have C# 2 or higher: 
    //form1.FormClosing += MyClosingEvent;