fast hiding main form

W

Wilfried Mestdagh

Hi,

I have an application with a main form, but I want to hide it as fast as
possible. Seems the only way to not show a single flicker is setting
Opacity = 0 in the constructor, and Visible = false; in Activate event.

Any better ways ?
 
M

Marc Gravell

Example using Application.Run() is below; if you are just going to .Show()
the form, then obviously lose the "using" or it will commit suicide too
early.
Note also the use of Load for the once-only startup event.

Also note that the below is NOT enough to hide it from [Alt]+[Tab] (try it
and see). You can achieve this using [DllImport] and a few Win32 calls
(possibly also in native C#)... but my example seems to have disappeared.
Let me know if you need this...

(perfect for hosting MP for a background route calculator... ;-p)

Marc

using (Form f = new Form())
{
f.StartPosition = FormStartPosition.Manual;
f.Location = new Point(-500, -500);
f.Size = new Size(200, 200);
f.ShowInTaskbar = false;
f.Load += delegate { f.Visible = false; };
Application.Run(f);
}
 
C

Chris Dunaway

Marc said:
Set the location to "manual" and place it off-screen? and very small?

While this may work, I think the best solution is not to show the form
at all. If the OP doesn't want the form visible, then he shoule not
show it!!

You can call Application.Run without showing a form. I presume that
the OP is trying to have an app that starts without showing a form and
perhaps has an icon in the system tray.
 
B

Ben Newsam

While this may work, I think the best solution is not to show the form
at all. If the OP doesn't want the form visible, then he shoule not
show it!!

You can call Application.Run without showing a form. I presume that
the OP is trying to have an app that starts without showing a form and
perhaps has an icon in the system tray.

I think he means he wants to make it disappear as soon as possible,
ie, like having a "boss key" when playing a game. Minimising or
closing it in the "normal" way might not be fast enough to keep it
from prying eyes.
 
W

Wilfried Mestdagh

Hi Chris,

I didn't realized you could call Application.Run without parameters. Yes
this works fine !
 

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