本文介绍了将代码中的表单关闭事件添加到特定对象实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的事情很简单,只是希望在窗体关闭后能够运行一些代码.

Pretty simple what I want to do, just want to be able to run some code after a form is closed.

Form1 f = new Form1();
f.Show();
f.formClosing ... <- I just want to run code from this context once this form has been closed

推荐答案

{
    Form1 f = new Form1();
    f.FormClosed += new FormClosedEventHandler(f_FormClosed);
    f.Show();
}

void f_FormClosed(object sender, FormClosedEventArgs e)
{
    // Do stuff here
}

这篇关于将代码中的表单关闭事件添加到特定对象实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 13:21