首先,您要处理主窗体的.FormClosing事件(或通过重写OnFormClosing方法).通过设置e.Cancel为true 取消.
然后,使用a NotifyIcon将图标添加到系统托盘.
最后,通过调用隐藏表单.Hide().
protected override void OnFormClosing(FormClosingEventArgs e) {
if (IActuallyWantToCloseFlag)
return;
var ni = new NotifyIcon(this.components)
{
Icon = someIcon,
Text = "My text",
Visible = true
};
ni.DoubleClick += (sender, args) => { this.Show(); };
this.Hide();
e.Cancel = true;
}
Run Code Online (Sandbox Code Playgroud)
这应该让你开始.您可能想要创建ni一个成员变量,以便在显示/隐藏表单时可以继续隐藏/显示图标.