I just want a c# application with a hidden main window that will process and respond to window messages.
I can create a form without showing it, and can then call Ap
Form1 f1=new Form1();
f1.WindowState = FormWindowState.Minimized;
f1.ShowInTaskbar = false;
The best way is to use the following 1-2 lines in the constuctor:
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false; // This is optional
You can even set the Minimized property in the VS Property window.
I know this is old question, but it ranks well in google, so I will provide my solution anyway.
I do two things:
private void Form_Load(object sender, EventArgs e)
{
Opacity = 0;
}
private void Form_Shown(object sender, EventArgs e)
{
Visible = false;
Opacity = 100;
}
You can create a class that inherits from System.Windows.Forms.NativeWindow
(which provides basic message loop capability) and reference the Handle
property in its constructor to create its handle and hook it into the message loop. Once you call Application.Run
, you will be able to process messages from it.
In the process of re-writing a VC++ TaskTray App, in C# .NET, I found the following method truly workable to achieve the following.
The steps I followed:
protected override void OnLoad(EventArgs e) { Visible = false; ShowInTaskbar = false; base.OnLoad(e); }
Why can't you just pass the form when you call Application.Run
? Given that it's clearly a blocking call, on what event do you want to show the form? Just calling form.Show()
should be enough.