很简单,我想要做的只是希望能够在窗体关闭后运行一些代码。将代码中的表单关闭事件添加到特定对象实例?
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.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
}
您可以处理Form.FormClosing事件。
this.FormClosing += new FormClosingEventHandler(myForm_FormClosing);
void myForm_FormClosing(object sender, FormClosingEventArgs e)
{
//your code here
}
this.FormClosing + =新System.Windows.Forms.FormClosingEventHandler(myForm_FormClosing); – Martin 2014-12-09 13:03:34
Form.FormClosing发生在窗体关闭之前。如果您取消此活动,表单将保持打开状态。
权事件来处理是Form.FormClosed:
form.FormClosed +=
new Form.FormClosedEventHandler(Place the name of the handler method here ...);
你怎么用VB.NET来做到这一点 – SamekaTV 2016-08-04 08:46:05