views:

33

answers:

2

What am I trying to achieve? I am writing a windows-form based application in C# .NET 2.0. The application should behave like this: No form should be visible; just a system tray icon is the entire application. So, I have to hide the form during startup and make a NotifyIcon available in the system tray with a ContextMenuStrip attached to it.

What have I done so far? I have created a Windows application with the default form's properties WindowState-Minimized and ShowInTaskbar-false. Added a NotifyIcon and attached a ContextMenuStrip to it.

What's happening? The application starts as a system tray icon and the form is hidden. So far so good. But when I am working with other applications and when I switch between other application using the Alt-Tab combination in Windows, the application icon appears in the switch-application menu; and when I select my application, the form appears.

What's expected? The application should not be available in the switch-application menu; because, the form is empty and there is no functionality attached to it. All that is needed is the system-tray icon.

How to hide the application entry from the switch-application menu?

Thanks.

+1  A: 

You can alter your program not to show the form at all, not even load it. Something like:

    [STAThread]
    static void Main()
    {

    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

    //Instance of your application/form
    NoForm hw = new NoForm();

    Application.Run(); //remove the Form oject from this call

    }

Your application should work and you'll have only your NotifyIcon shown.

Adrian Faciu
A: 

A Hide(); call in private void MainForm_Load(object sender, EventArgs e) solved this problem.

bdhar