My 1st form is frmLeaveRequest.
And My 2nd Form is frmLeaveRequestConfirmation.
There is a button named "Confirm" in 2nd form. I want to close those 2 forms when click on that button.
I tried to accomplish that task by following code.
frmLeaveRequest frm = new frmLeaveRequest()
frm.Close();
this.Close();
but it's doesn't work because it creates just a new object and not the same which I want to close.
Please give me a solution to accomplies that task.
//Form 1
private void button1_click(object sender, EventArgs e)
{
frmLeaveRequestConfirmation frmForm2 = new frmLeaveRequestConfirmation();
frmForm2.FormClosed += new FormClosedEventHandler(frmForm2_FormClosed);
frmForm2.Show();
}
private void frmForm2_FormClosed(object sender, FormClosedEventArgs e)
{
this.Close();
}
//Form 2
private void btnConfirm_Click(object sender, EventArgs e)
{
this.Close();
}
您可以将这些表单作为参数发送到新的表单构造函数,因此您可以引用它们并关闭它们。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.