im developing windows application using c#. i want to close the application and show new form after clicking the button, i did it, but every time i cliecked the button, it shows the another windows and when i going to task manager that form isntance still running. i want avoid that. i am using this.close() function to exit from the form.
im developing windows application using c#. i want to close the application and show
Share
Let’s suppose you have
Form1andForm2.The code in
Form1should be something like this:And in
Form2all you need to do is:Of course, you must suscribe to the event
FormClosinginForm2, but if you do it through the designer (FormProperties, clicking onEventsicon) just paste those two lines inside the method it creates)What is this code doing?
In
Form1:Form2Form1_FormClosingmethod, all we do is hide the form instead of closing it when the user closes it, and showing the instance ofForm2VisibleChangedeventForm2isn’t visible, thenForm1appears.In
Form2:If you want to do it when you click on a button, all you need to do is do the same but on the
Clickevent on the button instead of theFormClosingevent.