Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide form at launch

I have a program which only needs a NotifyIcon to work as intended. So I've been trying to get the main form to hide when the program starts.

In frmMain_Load, I tried both

this.Hide();
this.Visible = false;

without success.

They work in other methods, like in the NotifyIcon_MouseClick-method, but I want it to hide at Load.

I saw in another question here at SO where Matias suggested this:

BeginInvoke(new MethodInvoker(delegate
{
    Hide();
}));

This works, but when I launch the program I can see the form flashing real fast. It's better than nothing, but I wonder if there is any better solution to this.

Thanks.

like image 754
sippa Avatar asked Feb 06 '09 20:02

sippa


People also ask

How do you hide a form?

To hide a form it is necessary to call the Hide() method of the form to be hidden.

How do I hide the form on my taskbar?

To prevent your form from appearing in the taskbar, set its ShowInTaskbar property to False.

How do you hide and show a form?

To show or hide a form on a button click: Add a click event listener to the button element. Each time the button is clicked check if the form element is hidden. If the form is hidden, show it, otherwise hide the form.

How do I stop a windows form from closing?

To cancel the closure of a form, set the Cancel property of the CancelEventArgs passed to your event handler to true .


1 Answers

// In Your Program.cs Convert This
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
}

// To This
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Form1 TheForm = new Form1();
    Application.Run();
}

// Call Application.Exit() From Anywhere To Stop Application.Run() Message Pump and Exit Application
like image 70
VBNight Avatar answered Oct 21 '22 04:10

VBNight