Home All Groups Group Topic Archive Search About

Managing display of a form

Author
21 Oct 2006 3:36 PM
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

Author
21 Oct 2006 8:38 PM
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

-----
Tim Patrick
Start-to-Finish Visual Basic 2005


Show quoteHide quote
> 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
Author
22 Oct 2006 12:25 PM
rdufour
Thanks,

Bob

Show quoteHide quote
"Tim Patrick" <inva***@invalid.com.invalid> wrote in message
news:e3b46976056b8c8c32d45599c80@newsgroups.comcast.net...
> 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
>
> -----
> Tim Patrick
> Start-to-Finish Visual Basic 2005
>
>
>> 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
>
>