Managing display of a form

R

Robert Dufour

I have Form1 and Form2. Form2 has to be loaded in memory so that controls on
it can be controlled from Form1, so I declared it in the Form1 declaration
section. That works OK.
Now I just need to make form2 visible once and make it invisible again,
although it should be staying active in memory. If I have a global boolean
g_form2Shown then to show it I can, in a click event in form1 do

If not g_Form2Shown then
Form2.show 'the declaration was made in the form1 declaration section so
I don't have to dim the form as new here.
end if

However I don't want to unload Form2 from memory. It must continue to work
in the background. I just want to make it invisible. If I put a button on
Form 2 what code can I in it use to make it invisible but keep it working.

Thanks for any help
Bob
 
T

Tim Patrick

When you access forms globally by their name (as with "Form2.Show()"), you
are really accessing them via the My.Forms object (as in "My.Forms.Form2.Show()").
Once you access them, they stay in memory until you specifically set them
to nothing.

Form2 = Nothing

Within Form2, you can use the "Me.Hide()" method to make the form invisible.

If you don't want to use the global references to a form, you can create
an instance of a form and manipulate it that way.

Dim instanceOfForm2 As Form2
...
instanceOfForm2 = New Form2
instanceOfForm2.Show()
...
instanceOfForm2.Hide()
...
instanceOfForm2 = Nothing
 
R

rdufour

Thanks,

Bob

Tim Patrick said:
When you access forms globally by their name (as with "Form2.Show()"), you
are really accessing them via the My.Forms object (as in
"My.Forms.Form2.Show()"). Once you access them, they stay in memory until
you specifically set them to nothing.

Form2 = Nothing

Within Form2, you can use the "Me.Hide()" method to make the form
invisible.

If you don't want to use the global references to a form, you can create
an instance of a form and manipulate it that way.

Dim instanceOfForm2 As Form2
...
instanceOfForm2 = New Form2
instanceOfForm2.Show()
...
instanceOfForm2.Hide()
...
instanceOfForm2 = Nothing
 

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