Вопрос

Possible Duplicate:
How to make the startup form initially invisible or hidden

My application has a System Tray and I don't want the Window appearing on launch.

How can I accomplish this?


This is a default Windows Form application.

I dragged over a notifyIcon and a contexualMenuStrip

When the Form is closed, the application quits (don't want that either). But when the application is launched, the Windows Form is also made visible. So how do I not launch the form on start up (and not quit on closing the window)?

Это было полезно?

Другие советы

The answer isn't to hide your main form, but not to show it / load it in the first place.

One way is to create a custom ApplicationContext:

public static class Program
{
    public static void Main(string[] arguments)
    {
        var context = new NotifyIconApplicationContext();
        context.Icon.Icon = new Icon(PATH_TO_ICON_FILE_HERE);
        context.Icon.Visible = true;    
        Application.Run(context);
    }
}

class NotifyIconApplicationContext : ApplicationContext
{
    public NotifyIconApplicationContext()
    {
        Icon = new NotifyIcon();
    }
    public NotifyIcon Icon { get; set; }
}

You can then attach handlers to your notification icon prior to the Application.Run(context) line to allow for things like opening your main form, showing a menu, etc,..

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top