How to run an “empty” Windows Application that only has a NotifyIcon?

后端 未结 3 2180
不知归路
不知归路 2020-12-21 04:57

I want to make an Application that only has a NotifyIcon. It doesn\'t need to have at all a \"Main\" Form. When I want to achieve something like this, I just create an invis

相关标签:
3条回答
  • 2020-12-21 05:40

    From the same blog post @ChrisF mentioned https://bluehouse.wordpress.com/2006/01/24/how-to-create-a-notify-icon-in-c-without-a-form/

    The solution is more ridiculous than that …

    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    
    namespace DataUploader
    {
            static class Program
        {
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                NotifyIcon icn = new NotifyIcon();
                icn.Click += new EventHandler(icn_Click);
                icn.Visible = true;
                icn.Icon = new System.Drawing.Icon(@”SomeIcon.ico”);
                Application.Run();
            }
    
            static void icn_Click(object sender, EventArgs e)
            {
                Application.Exit();
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-21 05:43

    Another approach is to use special ApplicationContext which will have only the controls you need: Creating a Tasktray Application.

    0 讨论(0)
  • 2020-12-21 05:50

    Check out this blog post:

    As it turned out it was so easy it was ridiculous. All you have to do create a class that is inherits the iContainer interface. When you create the instance of the notify icon, pass a container object.

    It gives you the notify icon, but not a context menu.

    0 讨论(0)
提交回复
热议问题