C#如何创建一个后台运行的程序?

6

在相关的问题中,查看这个答案:https://dev59.com/fnVD5IYBdhLWcg3wOo9h#47743 - Jorge Ferreira
1个回答

6
  1. Drag and drop a NotifyIcon and a ContextMenuStrip.
  2. Set de NotifyIcon's context menu to the one you added
  3. Add 2 menuitems (e.g. Restore, Exit)
  4. Set the Form event resize and do the following check

    private void MyForm_Resize(object sender, EventArgs e)
    {
        if (this.WindowState == FormWindowState.Minimized) this.Hide();
        else this.Show();
    }
    
    // you could also restore the window with a
    // double click on the notify icon
    private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        this.Show();
        this.WindowState = FormWindowState.Normal;
    }
    

例如,可以下载这个项目

不用担心右键单击事件,NotifyIcon会自动检测并显示ContextMenu


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