In my program, there is a button you click that brings up a new form. This form runs a process. On the form (second form) closing event, I have

e.Cancel = true;

So now the form that runs the process is hidden. Now, the way i want it to work, is that when they click the button to open the form that runs the process *after* its been hidden, it should bring up the existing form instead of a new one. So basically the code for the button that opens form2 will have to check to see that the form is hidden, and if it is, show it. If its not hidden, open a new instance of it. The way i know how to open a new form is

Form2 frm = new Form2();

But the problem with that is that it opens a new instance every time. How can I show an existing hidden form?

Sorry if I seemed unclear.. let me know. Any help would be greatly appreciated.



9 Years
Discussion Span
Last Post by chaitra9

I *think* I see what you mean. Make the hidde form(from here referred to as formH) a member variable of the form with the open button(from here referred to as formO). That way, only one formH is ever declared and used, and is only destroyed when you telll it to, or close formO.

To do this, put a declaration for formH within the formO class braces, but not within any method blocks. To make the code easier to understand, it's mostly put directly before the formO() constructor.

Now that you have made a single formH available throughout the entire formO, when the open button is pressed, you need to pull it up. This code is pretty much self-explanatory:

//assuming you declared the formH as a variabled named formHInstance....
if (formHInstance == null)
    formHInstance == new formH();
Votes + Comments
Thanks for the help

When you closing any program in c sharp.


When you closing any program in vb (visual Basic).


Edited by hussain_ahmed: n/a


In my program,Im using a button in a form...when i click on it...it should open an existing form(Login form)...The thing is i knw how to open a new form when i click on button...but i need existing form which is already dr in ma system...im pissed off tryn dis...can anyone help me...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.