protected override void OnClosing(CancelEventArgs e) { if (minimize) { this.WindowState = WindowState.Minimized; this.ShowInTaskbar = false; NotifyWindow ballon = new NotifyWindow(); this.notifyInSysTry.ShowCustomBalloon(ballon, PopupAnimation.Slide, 4000); } else { notifyInSysTry.Dispose(); base.OnClosing(e); } e.Cancel = minimize = true; }