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
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
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted Jul 19, 2024, 6:29 AM EDT
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(); } }Rajadurai127 reputationPosted Jul 22, 2024, 12:24 AM EDT
Hi Amit,
Its working Thank you so much