开发者

Run Formless Notification User Control?

in my code i need to run notification control without showing any form how can i do it? i just add this code to program.cs main thread but it's not working please help me with this?

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run();
        TaskbarIcon tb = new TaskbarIcon();
        var balloon = new开发者_高级运维 Warning();
        tb.ShowCustomBalloon(balloon, PopupAnimation.Fade, 12000);

warning is a user control


I would recommend calling Application.Run() with an instance of ApplicationContext as parameter:

class Kernel : ApplicationContext
{
    private TaskbarIcon tb = new TaskbarIcon();

    public void Show()
    {
        var ballon = new Warning();
        tb.ShowCustomBalloon(balloon, PopupAnimation.Fade, 12000);
    }

    /// <summary>
    /// Closes the application.
    /// </summary>
    public void Close()
    {
        Application.Exit();
    }
}

Programm.cs:

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

using(var kernel = new Kernel())
{
    Application.Run(kernel);
}

This way it works with the default .NET NotifyIcon.


You could add a invisible form to serve as it's host if you want to. It's not nice, but it works for your scenario.

Another way to do it, would be to write your own tray icon + notify application, but I guess that's too much work for what you want to do.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜