Possible Duplicate:
Single Form Hide on Startup
I want to hide my WinForm after it run (Not minimizing).
I used:
this.Load += new System.EventHandler(this.Form1_Load);
private void Form1_Load(object sender, EventArgs e)
{
Hide();
}
But it's not working. Can you help me do it?
If you Don't want the user to be able to see the app at all set this: this. ShowInTaskbar = false; Then they won't be able to see the form in the task bar and it will be invisible.
Code to create a singleton object, public partial class Form2 : Form { ..... private static Form2 inst; public static Form2 GetForm { get { if (inst == null || inst. IsDisposed) inst = new Form2(); return inst; } } .... } Save this answer.
Although if you're not doing anything but returning from the form when you click the button, you could just set the DialogResult property on Form2. button1 in the form designer, and you wouldn't need an event handler in Form2 at all.
In the form Load override you can use one of the following tricks:
Make the form completely transparent:
private void OnFormLoad(object sender, EventArgs e)
{
Form form = (Form)sender;
form.ShowInTaskbar = false;
form.Opacity = 0;
}
Move the form way off the screen:
private void OnFormLoad(object sender, EventArgs e)
{
Form form = (Form)sender;
form.ShowInTaskbar = false;
form.Location = new Point(-10000, -10000);
}
Try to hide the form after it has been shown and not after it has been loaded, use the Shown event instead of the Load event
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With