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;
            Hide();

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();
frm.Show()

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.

Thanks,

SiPex

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();
}
formHInstance.Show();
commented: Thanks for the help +1

Thanks worked :)

When you closing any program in c sharp.

this.Hide();

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

Me.close()

Hi,
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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.