1

Currently, the form's opacity is 0%, so that when it loads, it should be invisible, but when the form loads, it's visible for a few seconds. Since the default opacity is set to 0% and the form's visibility is set to false before it's opacity is set back to 100%, I would think that the form should be invisible until I tell it to.

    public FormMain()
    {
        InitializeComponent();
        this.Visible = false;
        this.Opacity = 1.00;
    }

How can I make my form invisible as a default?

sooprise
  • 22,657
  • 67
  • 188
  • 276
  • When your program is being launched, `Application.Run(FormMain)`; makes the form visible. So if you want to Hide on load, add `this.Hide()` or `this.Visible = false` to it's Paint event or create an instance of `FormMain` and then invoke `Application.Run()` – fardjad Jan 25 '11 at 22:10
  • 3
    Duplicate....http://stackoverflow.com/questions/807005/c-net-winforms-instantiate-a-form-without-showing-it – Aaron McIver Jan 25 '11 at 22:11

2 Answers2

8

It's possible. You have to prevent the Application class from making the form visible. You cannot tinker with Application, that's locked up. But this works:

    protected override void SetVisibleCore(bool value) {
        if (!this.IsHandleCreated) {
            this.CreateHandle();
            value = false;
        }
        base.SetVisibleCore(value);
    }

This is a one-time cancellation, your next call to Show() or setting Visible = true will make it visible. You'd need some kind of trigger, a NotifyIcon context menu is typical. Beware that the Load event won't run until it actually gets visible. Everything else works like normal, calling the Close() method terminates the program.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
-1

You can use the Form_Shown event. When your main form shows, this event will be invoke and in there you can modify the properties of the form because is fully initialize. It's not the most aesthetic way. But is the only easy way I find.

private void Form1_Shown(object sender, EventArgs e)
{
    this.Visible = false;
}
jose loo
  • 1
  • 1