public TrayHandler(ObservationScheduler scheduler, ApplicationConfiguration configuration) { this.icon = new System.Windows.Forms.NotifyIcon(); this.icon.Icon = new Icon(Properties.Resources.Whatson, new Size(16, 16)); this.icon.Visible = true; this.scheduler = scheduler; this.configuration = configuration; this.contextMenu = new ContextMenu(); this.icon.ContextMenu = this.contextMenu; this.contextMenu.Popup += this.OnContextMenuPopup; this.icon.DoubleClick += (s, e) => this.ShowOrHideWindow(); this.icon.BalloonTipClicked += (s, e) => this.BringToFront(true); this.icon.Click += (s, e) => this.BringToFront(false); this.model = new NotificationsModel(this.scheduler); this.model.PropertyChanged += this.CurrentStatusPropertyChanged; if (File.Exists(Path.Combine(SerializationHelper.ConfigFolder, VisualSettingsFile))) { this.visualSettings = SerializationHelper.Load <MainWindowSettigns>(Path.Combine(SerializationHelper.ConfigFolder, VisualSettingsFile)); } if (!this.configuration.OpenMinimized) { this.ShowOrHideWindow(); } }
/// <summary> /// Called when user attempts to close <see cref="MainWindow"/>. It prevents window being closed and hides it instead. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event args.</param> private void MainWindowClosing(object sender, System.ComponentModel.CancelEventArgs e) { this.visualSettings = this.mainWindow.GetVisualSettigns(); }