Show hidden form1

R

Richard

Hello there,

I have a form that is called from a Sub Main procedure using
application.run(Form1).

On my main form there is a button to open an instance of Form2 and
then at the same time hide Form1.

So far so good.

What I would like to then do is to have a close button on Form2 which
closes Form2 (not a problem) but then re-shows the hidden form1 (or at
least the instance of the hidden form1).

Can anyone show me how to achieve this?

Thank you very much.



Richard
 
M

Michael C#

There are a ton of methods of referencing a form from another form. This is
probably one of the most common questions asked on these boards. Here's one
solution:

Create a Module and declare a variable of type Form1 and one of type Form2.
When the application starts, assign your start-up form to the Form1 variable
in the Module. Also instantiate (but hide) an instance of Form2 and assign
it to the Form2 variable in your module.
Now whenever you want Form1 to be shown, just hide Form2 and un-hide Form1
via the variables in the Module.

I.e.,

' From the Module
Dim f1 As Form1
Dim f2 As Form2

' In your form1 Load method
f1 = Me
f2 = New (Form2)

' When you want to show form1 and hide form2
f1.Visible = true
f2.Visible = false
f1.Activate()

' When you want to show form1 and hide form2
f2.Visible = true
f1.Visible = false
f2.Activate()

You'll need to cancel the Close event for each form or have some other
mechanism to tell when a form has been closed and needs to be re-created.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top