How can I close a different WinForm (B) from a different WinForm’s (A) code?
I already have it set up so WinForm (B) gets opened in WinForm (A)’s code:
Form2 form2 = new Form2();
form2.ShowDialog();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to make two changes to your code:
Showinstead ofShowDialogso that the first window can still handle events.Here’s some example code:
You will need to add some logic to make sure that you can’t close a form before you have opened it, and that you don’t try to close a form that you’ve already closed.