Opening a form hidden

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I have searched for answer to this question on the net but surprisingly no
clear answer has come up. How can I open a form hidden in vb.net?

Thanks

Regards
 
John said:
I have searched for answer to this question on the net but surprisingly no
clear answer has come up. How can I open a form hidden in vb.net?

Simply do not call the form's 'Show' or 'ShowDialog' method and do not set
its 'Visible' property to 'True'. You can use the form object by
instantiating the form class:

\\\
Dim f As New FooForm()
....
///

The form remains invisible until you show it.
 
I think he means main form (initial one)... It is not easy, because
setting Invisible=True is not working here...

There is official article at MSDN named "Setting a Form to Be
Invisible at Its Inception", but I found easier solution to set
opacity to 0% in designer and then just change it to 100% - effect is
same, but it is easier to implement. Only problem could be if you want
your application to run on older 9x clients - as far as I remember,
opacity is supported from Windows 2000.
 
Hi

I have searched for answer to this question on the net but surprisingly no
clear answer has come up. How can I open a form hidden in vb.net?

Thanks

Regards

Use Me.Hide() into your form_load event. Or try to set form's
visibility property to false.
 
I think he means main form (initial one)... It is not easy, because
setting Invisible=True is not working here...

There is official article at MSDN named "Setting a Form to Be
Invisible at Its Inception", but I found easier solution to set
opacity to 0% in designer and then just change it to 100% - effect is
same, but it is easier to implement. Only problem could be if you want
your application to run on older 9x clients - as far as I remember,
opacity is supported from Windows 2000.

Yes, setting visibility property to false might not work for some
reason (?), then setting opacity value to %0 seems a good alternative.
 
kimiraikkonen said:
Use Me.Hide() into your form_load event. Or try to set form's
visibility property to false.

When 'Load' is executed, the form is still not visible. In addition, the
form is shown after the 'Load' event has been executed.
 
kimiraikkonen said:
Use Me.Hide() into your form_load event. Or try to set form's
visibility property to false.


If the load event fires, there must have been a .Show before. Doesn't
make sense to Hide something because it's about to be Shown. Instead, I
wouldn't show it.


Armin
 
kimiraikkonen said:
Yes, setting visibility property to false might not work for some
reason (?), then setting opacity value to %0 seems a good
alternative.

A Form is a visual element in order to display something or accept
input. Showing an invisible thing is a contradiction in itself.

If the problem is the application framework that only allows a Form as
the startup object, disable it and write your own sub Main to get full
control over your own application. Then you can show the Form only if it
has to be shown.


Armin
 
You can set the position of the form off of the display, like to the right
of the user's screen, then move it back when you want to show it. Works like
a charm for me.

If you do this, don't let the cat sit on the right side of the monitor, so
he's not harmed when he's hit by the form flying over there... ;-)

RobinS.
GoldMail, Inc.
 
Be careful of systems with more than one monitor. What is off the
display on your system might be visible on another display on someone
else's system.
 
If the load event fires, there must have been a .Show before. Doesn't
make sense to Hide something because it's about to be Shown. Instead, I
wouldn't show it.

Armin

OK, in this case setting opacity to %0 seems really working way for
hiding form by default as stated previously.
 
Give me a teensy amount more credit than that. It pulls the info for the
screen, and positions the forms off the screen, regardless of how many
monitors, or the resolution, etc. :-)

RobinS.
-------------------------------------
 
Be careful of systems with more than one monitor. What is off the
display on your system might be visible on another display on someone
else's system.

I usually send it to -10000, if they that many monitors than they
deserve to see everything :-)

But in reality, I haven't sent a form off screen since my VB6 days,
now I usually just toggle the opacity between 0% and 99% when I have a
reason to hide and show a form. I do agree with Armin that Sub Main is
a better choice if no interaction is required, or the OP could just
create a service depending on the purpose of the app. And in case
anyone's wondering, whenever I use opacity I only go to 99%, going to
100% causes a flicker because of the way Windows paints forms (it has
two modes, one for opacity and one for no opacity, switching between
the two will flicker the form on painting).

Thanks,

Seth Rowe [MVP]
 
I have searched for answer to this question on the net

In my last post I also wanting to thank you for searching for the
answer before posting, but it slipped my mind. It's very much
appreciated when posters do the legwork before posting.

Thanks,

Seth Rowe [MVP]
 
This seems to scream "bad UI design"' to me.


RobinS said:
You can set the position of the form off of the display, like to the right
of the user's screen, then move it back when you want to show it. Works
like a charm for me.

If you do this, don't let the cat sit on the right side of the monitor, so
he's not harmed when he's hit by the form flying over there... ;-)

RobinS.
GoldMail, Inc.
 
Armin's got the right idea here....

Instead of playing tricks with the form (opacity, visibility, position,
etc.). Just take control of your application by using a Sub Main and then
you can launch the form whenever you need it.

While there are other *solutions*, they all scream of "hack".

-Scott
 
Armin's got the right idea here....

Instead of playing tricks with the form (opacity, visibility, position,
etc.).  Just take control of your application by using a Sub Main and then
you can launch the form whenever you need it.

While there are other *solutions*, they all scream of "hack".

-Scott







- Show quoted text -

Actually, moving the form offscreen has been recommended my the .NET
dev team for preventing flicker and drawing errors for MDI child
forms. Also, in more classic programming, moving forms and panels
offscreen was the recommended approach (take a look at how the VB6
wizard handles panels). Not saying they aren't "hacks", just sharing
some interesting tidbits. :-)

Thanks,

Seth Rowe [MVP]
 
Actually, moving the form offscreen has been recommended my the .NET
dev team for preventing flicker and drawing errors for MDI child
forms. Also, in more classic programming, moving forms and panels
offscreen was the recommended approach (take a look at how the VB6
wizard handles panels). Not saying they aren't "hacks", just sharing
some interesting tidbits. :-)

Seth Rowe [MVP]

Personally, I wouldn't look at much that was standard operating procedure in
VB 6.0 as a reason for doing it that way now. :)
 
Personally, I wouldn't look at much that was standard operating procedure in
VB 6.0 as a reason for doing it that way now. :)

You did read my earlier post right? I certainly don't advocate moving
the forms off screen to hide them (except in certain cases of mdi
children where nothing else will work), I was just sharing some
interesting information / history.

Thanks,

Seth Rowe [MVP]
 
Thanks! There's nothing like criticism without advice!

RobinS.
GoldMail, Inc.
-------------------
 
Back
Top