如何在没有窗体的情况下创建通知图标?

3

我将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个回答

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
谢谢。只需要通知图标1.Icon = SystemIcons.Asterisk; - BILL

0

当窗体最小化时,显示通知图标。请尝试此操作

 this.WindowState = FormWindowState.Minimized;

没有效果。图标没有出现。 - BILL

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接