我有一个带按钮的Form1。单击该按钮时,此代码块将执行:
Form2 frm = new Form2();
frm.Name = "Form" + musteriNumarasi.ToString();
frm.Text = "Kullanıcı - " + musteriNumarasi.ToString();
让我说我已经点击了三次。现在有四种形式:Main,Child1,Child2,Child3。当用户关闭其中一个子表单时,主表单需要知道哪一个表单已关闭。我怎么能这样做?
答案 0 :(得分:13)
订阅Closed Event
Form2 frm = new Form2();
frm.FormClosed += new FormClosedEventHandler(Form_Closed);
void Form_Closed(object sender, FormClosedEventArgs e)
{
Form2 frm = (Form2)sender;
MessageBox.Show(frm.Name);
}
答案 1 :(得分:0)
Form2 frm = new Form2();
frm.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.frm _FormClosed);
。 。
private void frm_FormClosed(object sender, EventArgs e)
{
//Runs after closing child :)
}
答案 2 :(得分:-2)
将这些行添加到您的代码中以处理已关闭或关闭表单的事件
frm.Closing += Form_Closing;
frm.Closed += Form_Closed;
将以下方法添加到当前的类
void Form_Closing (object sender,EventArgs e){
//Handler form Closing Event
}
void Form_Closed (object sender,EventArgs e){
//Handler form Closed Event
}