Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide WinForm after it run? [duplicate]

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?

like image 748
Thanh Nguyen Avatar asked Jan 22 '13 09:01

Thanh Nguyen


People also ask

How do I hide winform?

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.

How do I stop multiple windows forms from opening in C#?

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.

How do I go back to previous form in C#?

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.


2 Answers

In the form Load override you can use one of the following tricks:

  1. Make the form completely transparent:

    private void OnFormLoad(object sender, EventArgs e)
    {
         Form form = (Form)sender;
         form.ShowInTaskbar = false;
         form.Opacity = 0;
    }
    
  2. 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);
    } 
    
like image 146
Pavel Vladov Avatar answered Oct 07 '22 09:10

Pavel Vladov


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

like image 32
polkduran Avatar answered Oct 07 '22 08:10

polkduran