如何在没有Form的情况下创建notifyIcon?

时间:2011-04-12 11:00:58

标签: c# forms notifyicon

我将notifyIcon添加到容器中并设置了Visible = true选项,但没有出现图标。

private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
            this.SuspendLayout();
            // 
            // notifyIcon1
            // 
            this.notifyIcon1.Text = "Manager";
            this.notifyIcon1.Visible = true;
            // 
            // Form1
            // 
            this.ClientSize = new System.Drawing.Size(0, 0);
            this.ShowInTaskbar = false;
            this.Visible = false;

        }

2 个答案:

答案 0 :(得分:2)

我相信你需要再添加一些活动才能发挥作用,希望这会有所帮助

public Form2()
    {
        InitializeComponent();
        notifyIcon1.Icon = SystemIcons.Asterisk;
        notifyIcon1.DoubleClick += new EventHandler(notifyIcon1_DoubleClick);// to bring it back
        this.Resize += new EventHandler(Form2_Resize);// to move it to tray
    }

    void notifyIcon1_DoubleClick(object sender, EventArgs e)
    {
        Show();
        this.BringToFront();
        this.WindowState = FormWindowState.Normal;
    }

    void Form2_Resize(object sender, EventArgs e)
    {
        if (this.WindowState ==FormWindowState.Minimized)
            Hide();
    }

答案 1 :(得分:0)

表单最小化时显示

notify图标。试试这个

 this.WindowState = FormWindowState.Minimized;