开发者

C# Run Windows Form App not starting with a form

I want my program to start with a balloon icon and once it is clicked for a window to come up but when I try to run a class I made that shows the message, I cant run it because it's not a form. Basically I could get a ba开发者_高级运维lloon alert to pop up but Once clicked it would not open the form because it seems like the program already terminated (Main() in Program.cs already finished)

I tried stuff like this:

static void Main() {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        new TrayIcon();
    }

but it just shows the alert and doesn't work.

If I make my TrayIcon Class a partial Form and Used Application.Run() It works but an empty, ugly form pops up too.

So how can I just make the balloon pop up at first without the program ending?


Just use the Application.Run overload that does not take a Form parameter:

static void Main() 
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

    new TrayIcon();
    Application.Run();
}

This will start a Windows message loop on the current thread, which will process UI messages, including those necessary for your notifyicon to become visible and responsive.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜