private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing && State != Models.State.Terminating) { // 取消"关闭窗口"事件 e.Cancel = true; // 取消关闭窗体 // 如果未勾选关闭窗口时退出,隐藏至右下角托盘图标 if (!Global.Settings.ExitWhenClosed) { // 使关闭时窗口向右下角缩小的效果 WindowState = FormWindowState.Minimized; NotifyIcon.Visible = true; if (IsFirstOpened) { // 显示提示语 NotifyIcon.ShowBalloonTip(5, UpdateChecker.Name, Utils.i18N.Translate("Netch is now minimized to the notification bar, double click this icon to restore."), ToolTipIcon.Info); IsFirstOpened = false; } Hide(); } // 如果勾选了关闭时退出,自动点击退出按钮 else { ExitToolStripButton.PerformClick(); } } }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing && State != Models.State.Terminating) { // 取消"关闭窗口"事件 e.Cancel = true; // 取消关闭窗体 // 如果未勾选关闭窗口时退出,隐藏至右下角托盘图标 if (!Global.Settings.ExitWhenClosed) { // 使关闭时窗口向右下角缩小的效果 this.WindowState = FormWindowState.Minimized; this.NotifyIcon.Visible = true; if (IsFirstOpened) { // 显示提示语 this.NotifyIcon.BalloonTipTitle = "Netch"; this.NotifyIcon.BalloonTipIcon = ToolTipIcon.Info; this.NotifyIcon.ShowBalloonTip(5); IsFirstOpened = false; } Hide(); } // 如果勾选了关闭时退出,自动点击退出按钮 else { ExitToolStripButton.PerformClick(); } } }