protected override void Dispose(bool disposing) { if (disposing) { if (this.trayIcon != null) { this.trayIcon.Dispose(); this.trayIcon = null; } if (this.timer != null) { this.timer.Dispose(); this.timer = null; } if (this.statusWindow != null) { this.statusWindow.Dispose(); this.statusWindow = null; } } base.Dispose(disposing); }
private void OptionsDialog_Load(object sender, EventArgs e) { this.UpdateControls(); if (!this.formSaver.Load()) { StatusWindow.MoveNearSystemTray(this); } }
private Program() { // Load options first. using (ISettingsStore store = ApplicationInfo.CreateUserSettingsStore()) { Options.Load(store.RootNode); } // Create a tray icon with no parent form. // http://bluehouse.wordpress.com/2006/01/24/how-to-create-a-notify-icon-in-c-without-a-form/ this.trayIcon = new NotifyIcon(); this.trayIcon.Visible = true; this.trayIcon.Icon = new Icon(Properties.Resources.Icon16_Stopwatch_00, SystemInformation.SmallIconSize); this.trayIcon.ContextMenuStrip = new ContextMenuStrip(); this.trayIcon.DoubleClick += this.ShowStatus_Click; // Windows uses the tooltip text to identify an icon for its tray notification settings. // So the tooltip needs to be predictable and consistent for Windows to match it up // correctly. If this includes variable data (e.g., working time), then Windows will // treat each instance as a unique instance, which sucks. this.trayIcon.Text = ApplicationInfo.ApplicationName; // Set up the context menu. ToolStripItemCollection menuItems = this.trayIcon.ContextMenuStrip.Items; menuItems.Add("&Show Status", null, this.ShowStatus_Click); menuItems.Add("&Reset Timer", null, this.ResetTimer_Click); menuItems.Add("-"); menuItems.Add("Options...", null, this.Options_Click); menuItems.Add("About...", null, this.About_Click); menuItems.Add("-"); menuItems.Add("E&xit", null, this.Exit_Click); // Create the status window, but don't show it yet. this.statusWindow = new StatusWindow(); this.statusWindow.VisibleChanged += this.StatusWindow_VisibleChanged; // Set up the timer. this.timer = new System.Windows.Forms.Timer(); this.timer.Interval = (int)TimeSpan.FromSeconds(1).TotalMilliseconds; this.timer.Tick += this.Timer_Tick; this.timer.Start(); }