GUI/MainForm.cs
changeset 82 91edecb084a1
parent 71 9b08df4bf2f2
child 83 3fdadd4a830f
     1.1 --- a/GUI/MainForm.cs	Mon Mar 22 17:58:21 2010 +0000
     1.2 +++ b/GUI/MainForm.cs	Fri Mar 26 20:58:10 2010 +0000
     1.3 @@ -58,6 +58,7 @@
     1.4      private Color[] plotColorPalette;
     1.5      private SensorSystemTray sensorSystemTray;
     1.6      private NotifyIcon notifyIcon;
     1.7 +    private StartupManager startupManager = new StartupManager();
     1.8  
     1.9      public MainForm() {      
    1.10        InitializeComponent();
    1.11 @@ -105,7 +106,7 @@
    1.12        notifyIcon.ContextMenuStrip = this.notifyContextMenuStrip;
    1.13        notifyIcon.Icon = EmbeddedResources.GetIcon("smallicon.ico");
    1.14        notifyIcon.Text = "Open Hardware Monitor";      
    1.15 -      notifyIcon.DoubleClick += new EventHandler(this.restoreClick);
    1.16 +      notifyIcon.DoubleClick += new EventHandler(this.hideShowClick);
    1.17  
    1.18        sensorSystemTray = new SensorSystemTray(computer);
    1.19  
    1.20 @@ -136,6 +137,7 @@
    1.21  
    1.22        startMinMenuItem.Checked = Config.Get(startMinMenuItem.Name, false); 
    1.23        minTrayMenuItem.Checked = Config.Get(minTrayMenuItem.Name, true);
    1.24 +      startupMenuItem.Checked = startupManager.Startup;
    1.25        hddMenuItem.Checked = Config.Get(hddMenuItem.Name, true);
    1.26  
    1.27        voltMenuItem.Checked = Config.Get(voltMenuItem.Name, true);
    1.28 @@ -148,9 +150,7 @@
    1.29        timer.Enabled = true;
    1.30  
    1.31        if (startMinMenuItem.Checked) {
    1.32 -        if (minTrayMenuItem.Checked) {
    1.33 -          notifyIcon.Visible = true;
    1.34 -        } else {
    1.35 +        if (!minTrayMenuItem.Checked) {
    1.36            WindowState = FormWindowState.Minimized;
    1.37            Show();
    1.38          }
    1.39 @@ -273,7 +273,7 @@
    1.40        Config.Set(loadMenuItem.Name, loadMenuItem.Checked);
    1.41        Config.Set(tempMenuItem.Name, tempMenuItem.Checked);
    1.42        Config.Set(fansMenuItem.Name, fansMenuItem.Checked);
    1.43 -      Config.Set(flowsMenuItem.Name, flowsMenuItem.Checked);
    1.44 +      Config.Set(flowsMenuItem.Name, flowsMenuItem.Checked);      
    1.45  
    1.46        if (WindowState != FormWindowState.Minimized) {
    1.47          Config.Set("mainForm.Location.X", Location.X);
    1.48 @@ -391,15 +391,10 @@
    1.49          UpdateSensorTypeVisible(node);
    1.50      }
    1.51  
    1.52 -    private void ToggleSysTray() {
    1.53 -      if (notifyIcon.Visible) {
    1.54 -        Visible = true;
    1.55 -        notifyIcon.Visible = false;
    1.56 -        Activate(); 
    1.57 -      } else {
    1.58 -        notifyIcon.Visible = true;
    1.59 -        Visible = false;           
    1.60 -      }
    1.61 +    private void SysTrayHideShow() {
    1.62 +      Visible = !Visible;
    1.63 +      if (Visible)
    1.64 +        Activate();    
    1.65      }
    1.66  
    1.67      protected override void WndProc(ref Message m) {
    1.68 @@ -407,14 +402,14 @@
    1.69        const int SC_MINIMIZE = 0xF020;
    1.70        if (minTrayMenuItem.Checked && 
    1.71          m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE) {
    1.72 -        ToggleSysTray();
    1.73 +        SysTrayHideShow();
    1.74        } else {      
    1.75          base.WndProc(ref m);
    1.76        }
    1.77      }
    1.78  
    1.79 -    private void restoreClick(object sender, EventArgs e) {
    1.80 -      ToggleSysTray();
    1.81 +    private void hideShowClick(object sender, EventArgs e) {
    1.82 +      SysTrayHideShow();
    1.83      }
    1.84  
    1.85      private void removeToolStripMenuItem_Click(object sender, EventArgs e) {
    1.86 @@ -444,5 +439,15 @@
    1.87          ShowParameterForm(node.Sensor);
    1.88        }
    1.89      }
    1.90 +
    1.91 +    private void runOnWindowsStartupToolStripMenuItem_CheckedChanged(
    1.92 +      object sender, EventArgs e) 
    1.93 +    {
    1.94 +      startupManager.Startup = startupMenuItem.Checked;
    1.95 +    }
    1.96 +
    1.97 +    private void minTrayMenuItem_CheckedChanged(object sender, EventArgs e) {
    1.98 +      notifyIcon.Visible = minTrayMenuItem.Checked;
    1.99 +    }
   1.100    }
   1.101  }