Rajadurai
Hi Masters,
how to close form 2 from form1 click button in windows form using c#
I have 2 Forms , Form1 and Form 2
please advise simple method
Thanks
Try the below code:
private void Button_Click(object sender, EventArgs e) { Form formToClose = null; foreach (Form form in Application.OpenForms) { if (form is Form2) { formToClose = form; break; // Exit the loop once Form2 is found } } if (formToClose != null) { formToClose.Close(); } }
Hi Amit,
Its working Thank you so much