如何在最小化时将.net应用程序放入系统托盘中?

bug*_*ger 9 .net system system-tray

任何人都可以建议一个良好的代码示例 vb.net/c#代码,以便在缩小时将应用程序放入系统托盘.

Phi*_*lls 18

将NotifyIcon控件添加到表单,然后使用以下代码:

    private void frm_main_Resize(object sender, EventArgs e)
    {
        if (this.WindowState == FormWindowState.Minimized)
        {
           this.ShowInTaskbar = false;
           this.Hide();
           notifyIcon1.Visible = true;
        }
    }

    private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        this.Show();
        this.WindowState = FormWindowState.Normal;
        this.ShowInTaskbar = true;
        notifyIcon1.Visible = false;
    }
Run Code Online (Sandbox Code Playgroud)

您可能不需要设置ShowInTaskbar属性.