Removed the bitmap.GetHbitmap call for every redraw of the gadget. This should reduce dynamic memory allocation and freeing and removes some of the page faults increasing.
3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2009-2011
20 the Initial Developer. All Rights Reserved.
22 Contributor(s): Paul Werelds
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
39 using System.Collections.Generic;
40 using System.ComponentModel;
43 using System.Reflection;
44 using System.Windows.Forms;
45 using Aga.Controls.Tree;
46 using Aga.Controls.Tree.NodeControls;
47 using OpenHardwareMonitor.Hardware;
48 using OpenHardwareMonitor.WMI;
50 namespace OpenHardwareMonitor.GUI {
51 public partial class MainForm : Form {
53 private PersistentSettings settings;
54 private UnitManager unitManager;
55 private Computer computer;
57 private TreeModel treeModel;
58 private IDictionary<ISensor, Color> sensorPlotColors =
59 new Dictionary<ISensor, Color>();
60 private Color[] plotColorPalette;
61 private SystemTray systemTray;
62 private StartupManager startupManager = new StartupManager();
63 private UpdateVisitor updateVisitor = new UpdateVisitor();
64 private SensorGadget gadget;
65 private Form plotForm;
67 private UserOption showHiddenSensors;
68 private UserOption showPlot;
69 private UserOption showValue;
70 private UserOption showMin;
71 private UserOption showMax;
72 private UserOption startMinimized;
73 private UserOption minimizeToTray;
74 private UserOption minimizeOnClose;
75 private UserOption autoStart;
76 private UserOption readHddSensors;
77 private UserOption showGadget;
78 private UserRadioGroup plotLocation;
80 private WmiProvider wmiProvider;
82 private bool selectionDragging = false;
85 InitializeComponent();
87 // check if the OpenHardwareMonitorLib assembly has the correct version
88 if (Assembly.GetAssembly(typeof(Computer)).GetName().Version !=
89 Assembly.GetExecutingAssembly().GetName().Version) {
91 "The version of the file OpenHardwareMonitorLib.dll is incompatible.",
92 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
96 this.settings = new PersistentSettings();
97 this.settings.Load(Path.ChangeExtension(
98 Application.ExecutablePath, ".config"));
100 this.unitManager = new UnitManager(settings);
102 // set the DockStyle here, to avoid conflicts with the MainMenu
103 this.splitContainer.Dock = DockStyle.Fill;
105 this.Font = SystemFonts.MessageBoxFont;
106 treeView.Font = SystemFonts.MessageBoxFont;
107 plotPanel.Font = SystemFonts.MessageBoxFont;
109 nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded;
110 nodeCheckBox.CheckStateChanged += UpdatePlotSelection;
111 nodeTextBoxText.DrawText += nodeTextBoxText_DrawText;
112 nodeTextBoxValue.DrawText += nodeTextBoxText_DrawText;
113 nodeTextBoxMin.DrawText += nodeTextBoxText_DrawText;
114 nodeTextBoxMax.DrawText += nodeTextBoxText_DrawText;
115 nodeTextBoxText.EditorShowing += nodeTextBoxText_EditorShowing;
117 foreach (TreeColumn column in treeView.Columns)
118 column.Width = Math.Max(20, Math.Min(400,
119 settings.GetValue("treeView.Columns." + column.Header + ".Width",
122 treeModel = new TreeModel();
123 root = new Node(System.Environment.MachineName);
124 root.Image = Utilities.EmbeddedResources.GetImage("computer.png");
126 treeModel.Nodes.Add(root);
127 treeView.Model = treeModel;
129 this.computer = new Computer(settings);
131 systemTray = new SystemTray(computer, settings);
132 systemTray.HideShowCommand += hideShowClick;
133 systemTray.ExitCommand += exitClick;
135 int p = (int)Environment.OSVersion.Platform;
136 if ((p == 4) || (p == 128)) { // Unix
137 treeView.RowHeight = Math.Max(treeView.RowHeight, 18);
138 splitContainer.BorderStyle = BorderStyle.None;
139 splitContainer.Border3DStyle = Border3DStyle.Adjust;
140 splitContainer.SplitterWidth = 4;
141 treeView.BorderStyle = BorderStyle.Fixed3D;
142 plotPanel.BorderStyle = BorderStyle.Fixed3D;
143 gadgetMenuItem.Visible = false;
144 minCloseMenuItem.Visible = false;
145 minTrayMenuItem.Visible = false;
146 startMinMenuItem.Visible = false;
148 treeView.RowHeight = Math.Max(treeView.Font.Height + 1, 18);
150 gadget = new SensorGadget(computer, settings, unitManager);
151 gadget.HideShowCommand += hideShowClick;
153 wmiProvider = new WmiProvider(computer);
156 computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
157 computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
161 timer.Enabled = true;
163 plotColorPalette = new Color[13];
164 plotColorPalette[0] = Color.Blue;
165 plotColorPalette[1] = Color.OrangeRed;
166 plotColorPalette[2] = Color.Green;
167 plotColorPalette[3] = Color.LightSeaGreen;
168 plotColorPalette[4] = Color.Goldenrod;
169 plotColorPalette[5] = Color.DarkViolet;
170 plotColorPalette[6] = Color.YellowGreen;
171 plotColorPalette[7] = Color.SaddleBrown;
172 plotColorPalette[8] = Color.RoyalBlue;
173 plotColorPalette[9] = Color.DeepPink;
174 plotColorPalette[10] = Color.MediumSeaGreen;
175 plotColorPalette[11] = Color.Olive;
176 plotColorPalette[12] = Color.Firebrick;
178 showHiddenSensors = new UserOption("hiddenMenuItem", false,
179 hiddenMenuItem, settings);
180 showHiddenSensors.Changed += delegate(object sender, EventArgs e) {
181 treeModel.ForceVisible = showHiddenSensors.Value;
184 showValue = new UserOption("valueMenuItem", true, valueMenuItem,
186 showValue.Changed += delegate(object sender, EventArgs e) {
187 treeView.Columns[1].IsVisible = showValue.Value;
190 showMin = new UserOption("minMenuItem", false, minMenuItem, settings);
191 showMin.Changed += delegate(object sender, EventArgs e) {
192 treeView.Columns[2].IsVisible = showMin.Value;
195 showMax = new UserOption("maxMenuItem", true, maxMenuItem, settings);
196 showMax.Changed += delegate(object sender, EventArgs e) {
197 treeView.Columns[3].IsVisible = showMax.Value;
200 startMinimized = new UserOption("startMinMenuItem", false,
201 startMinMenuItem, settings);
203 minimizeToTray = new UserOption("minTrayMenuItem", true,
204 minTrayMenuItem, settings);
205 minimizeToTray.Changed += delegate(object sender, EventArgs e) {
206 systemTray.IsMainIconEnabled = minimizeToTray.Value;
209 minimizeOnClose = new UserOption("minCloseMenuItem", false,
210 minCloseMenuItem, settings);
212 autoStart = new UserOption(null, startupManager.Startup,
213 startupMenuItem, settings);
214 autoStart.Changed += delegate(object sender, EventArgs e) {
216 startupManager.Startup = autoStart.Value;
217 } catch (InvalidOperationException) {
218 MessageBox.Show("Updating the auto-startup option failed.", "Error",
219 MessageBoxButtons.OK, MessageBoxIcon.Error);
220 autoStart.Value = startupManager.Startup;
224 readHddSensors = new UserOption("hddMenuItem", true, hddMenuItem,
226 readHddSensors.Changed += delegate(object sender, EventArgs e) {
227 computer.HDDEnabled = readHddSensors.Value;
228 UpdatePlotSelection(null, null);
231 showGadget = new UserOption("gadgetMenuItem", false, gadgetMenuItem,
233 showGadget.Changed += delegate(object sender, EventArgs e) {
235 gadget.Visible = showGadget.Value;
238 celsiusMenuItem.Checked =
239 unitManager.TemperatureUnit == TemperatureUnit.Celsius;
240 fahrenheitMenuItem.Checked = !celsiusMenuItem.Checked;
242 InitializePlotForm();
244 startupMenuItem.Visible = startupManager.IsAvailable;
246 if (startMinMenuItem.Checked) {
247 if (!minTrayMenuItem.Checked) {
248 WindowState = FormWindowState.Minimized;
255 // Create a handle, otherwise calling Close() does not fire FormClosed
256 IntPtr handle = Handle;
258 // Make sure the settings are saved when the user logs off
259 Microsoft.Win32.SystemEvents.SessionEnded += delegate {
264 private void InitializePlotForm() {
265 plotForm = new Form();
266 plotForm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
267 plotForm.ShowInTaskbar = false;
268 plotForm.StartPosition = FormStartPosition.Manual;
269 this.AddOwnedForm(plotForm);
270 plotForm.Bounds = new Rectangle {
271 X = settings.GetValue("plotForm.Location.X", -100000),
272 Y = settings.GetValue("plotForm.Location.Y", 100),
273 Width = settings.GetValue("plotForm.Width", 600),
274 Height = settings.GetValue("plotForm.Height", 400)
277 showPlot = new UserOption("plotMenuItem", false, plotMenuItem, settings);
278 plotLocation = new UserRadioGroup("plotLocation", 0,
279 new[] { plotWindowMenuItem, plotBottomMenuItem, plotRightMenuItem },
282 showPlot.Changed += delegate(object sender, EventArgs e) {
283 if (plotLocation.Value == 0) {
284 if (showPlot.Value && this.Visible)
289 splitContainer.Panel2Collapsed = !showPlot.Value;
291 treeView.Invalidate();
293 plotLocation.Changed += delegate(object sender, EventArgs e) {
294 switch (plotLocation.Value) {
296 splitContainer.Panel2.Controls.Clear();
297 splitContainer.Panel2Collapsed = true;
298 plotForm.Controls.Add(plotPanel);
299 if (showPlot.Value && this.Visible)
303 plotForm.Controls.Clear();
305 splitContainer.Orientation = Orientation.Horizontal;
306 splitContainer.Panel2.Controls.Add(plotPanel);
307 splitContainer.Panel2Collapsed = !showPlot.Value;
310 plotForm.Controls.Clear();
312 splitContainer.Orientation = Orientation.Vertical;
313 splitContainer.Panel2.Controls.Add(plotPanel);
314 splitContainer.Panel2Collapsed = !showPlot.Value;
319 plotForm.FormClosing += delegate(object sender, FormClosingEventArgs e) {
320 if (e.CloseReason == CloseReason.UserClosing) {
321 // just switch off the plotting when the user closes the form
322 if (plotLocation.Value == 0) {
323 showPlot.Value = false;
329 EventHandler moveOrResizePlotForm = delegate(object sender, EventArgs e) {
330 if (plotForm.WindowState != FormWindowState.Minimized) {
331 settings.SetValue("plotForm.Location.X", plotForm.Bounds.X);
332 settings.SetValue("plotForm.Location.Y", plotForm.Bounds.Y);
333 settings.SetValue("plotForm.Width", plotForm.Bounds.Width);
334 settings.SetValue("plotForm.Height", plotForm.Bounds.Height);
337 plotForm.Move += moveOrResizePlotForm;
338 plotForm.Resize += moveOrResizePlotForm;
340 plotForm.VisibleChanged += delegate(object sender, EventArgs e) {
341 Rectangle bounds = new Rectangle(plotForm.Location, plotForm.Size);
342 Screen screen = Screen.FromRectangle(bounds);
343 Rectangle intersection =
344 Rectangle.Intersect(screen.WorkingArea, bounds);
345 if (intersection.Width < Math.Min(16, bounds.Width) ||
346 intersection.Height < Math.Min(16, bounds.Height)) {
347 plotForm.Location = new Point(
348 screen.WorkingArea.Width / 2 - bounds.Width / 2,
349 screen.WorkingArea.Height / 2 - bounds.Height / 2);
353 this.VisibleChanged += delegate(object sender, EventArgs e) {
354 if (this.Visible && showPlot.Value && plotLocation.Value == 0)
361 private void SubHardwareAdded(IHardware hardware, Node node) {
362 Node hardwareNode = new HardwareNode(hardware, settings, unitManager);
363 node.Nodes.Add(hardwareNode);
364 foreach (IHardware subHardware in hardware.SubHardware)
365 SubHardwareAdded(subHardware, hardwareNode);
368 private void HardwareAdded(IHardware hardware) {
369 Node hardwareNode = new HardwareNode(hardware, settings, unitManager);
370 root.Nodes.Add(hardwareNode);
371 foreach (IHardware subHardware in hardware.SubHardware)
372 SubHardwareAdded(subHardware, hardwareNode);
375 private void HardwareRemoved(IHardware hardware) {
376 List<Node> nodesToRemove = new List<Node>();
377 foreach (Node node in root.Nodes) {
378 HardwareNode hardwareNode = node as HardwareNode;
379 if (hardwareNode != null && hardwareNode.Hardware == hardware)
380 nodesToRemove.Add(node);
382 foreach (Node node in nodesToRemove)
383 root.Nodes.Remove(node);
386 private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e) {
387 Node node = e.Node.Tag as Node;
390 if (node.IsVisible) {
391 SensorNode sensorNode = node as SensorNode;
392 if (plotMenuItem.Checked && sensorNode != null &&
393 sensorPlotColors.TryGetValue(sensorNode.Sensor, out color))
396 e.TextColor = Color.DarkGray;
401 private void UpdatePlotSelection(object sender,
404 List<ISensor> selected = new List<ISensor>();
405 IDictionary<ISensor, Color> colors = new Dictionary<ISensor, Color>();
407 foreach (TreeNodeAdv node in treeView.AllNodes) {
408 SensorNode sensorNode = node.Tag as SensorNode;
409 if (sensorNode != null &&
410 sensorNode.Sensor.SensorType == SensorType.Temperature) {
411 if (sensorNode.Plot) {
412 colors.Add(sensorNode.Sensor,
413 plotColorPalette[colorIndex % plotColorPalette.Length]);
414 selected.Add(sensorNode.Sensor);
419 sensorPlotColors = colors;
420 plotPanel.SetSensors(selected, colors);
423 private void nodeTextBoxText_EditorShowing(object sender,
426 e.Cancel = !(treeView.CurrentNode != null &&
427 (treeView.CurrentNode.Tag is SensorNode ||
428 treeView.CurrentNode.Tag is HardwareNode));
431 private void nodeCheckBox_IsVisibleValueNeeded(object sender,
432 NodeControlValueEventArgs e) {
433 SensorNode node = e.Node.Tag as SensorNode;
434 e.Value = (node != null) &&
435 (node.Sensor.SensorType == SensorType.Temperature) &&
436 plotMenuItem.Checked;
439 private void exitClick(object sender, EventArgs e) {
443 private void timer_Tick(object sender, EventArgs e) {
444 computer.Accept(updateVisitor);
445 treeView.Invalidate();
446 plotPanel.Invalidate();
451 if (wmiProvider != null)
452 wmiProvider.Update();
455 private void SaveConfiguration() {
456 foreach (TreeColumn column in treeView.Columns)
457 settings.SetValue("treeView.Columns." + column.Header + ".Width",
460 string fileName = Path.ChangeExtension(
461 System.Windows.Forms.Application.ExecutablePath, ".config");
463 settings.Save(fileName);
464 } catch (UnauthorizedAccessException) {
465 MessageBox.Show("Access to the path '" + fileName + "' is denied. " +
466 "The current settings could not be saved.",
467 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
468 } catch (IOException) {
469 MessageBox.Show("The path '" + fileName + "' is not writeable. " +
470 "The current settings could not be saved.",
471 "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
475 private void MainForm_Load(object sender, EventArgs e) {
476 Rectangle newBounds = new Rectangle {
477 X = settings.GetValue("mainForm.Location.X", Location.X),
478 Y = settings.GetValue("mainForm.Location.Y", Location.Y),
479 Width = settings.GetValue("mainForm.Width", 470),
480 Height = settings.GetValue("mainForm.Height", 640)
483 Rectangle fullWorkingArea = new Rectangle(int.MaxValue, int.MaxValue,
484 int.MinValue, int.MinValue);
486 foreach (Screen screen in Screen.AllScreens)
487 fullWorkingArea = Rectangle.Union(fullWorkingArea, screen.Bounds);
489 Rectangle intersection = Rectangle.Intersect(fullWorkingArea, newBounds);
490 if (intersection.Width < 20 || intersection.Height < 20 ||
491 !settings.Contains("mainForm.Location.X")
493 newBounds.X = (Screen.PrimaryScreen.WorkingArea.Width / 2) -
496 newBounds.Y = (Screen.PrimaryScreen.WorkingArea.Height / 2) -
497 (newBounds.Height / 2);
500 this.Bounds = newBounds;
503 private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
505 systemTray.IsMainIconEnabled = false;
506 timer.Enabled = false;
509 systemTray.Dispose();
512 private void aboutMenuItem_Click(object sender, EventArgs e) {
513 new AboutBox().ShowDialog();
516 private void treeView_Click(object sender, EventArgs e) {
518 MouseEventArgs m = e as MouseEventArgs;
519 if (m == null || m.Button != MouseButtons.Right)
522 NodeControlInfo info = treeView.GetNodeControlInfoAt(
525 treeView.SelectedNode = info.Node;
526 if (info.Node != null) {
527 SensorNode node = info.Node.Tag as SensorNode;
528 if (node != null && node.Sensor != null) {
529 treeContextMenu.MenuItems.Clear();
530 if (node.Sensor.Parameters.Length > 0) {
531 MenuItem item = new MenuItem("Parameters...");
532 item.Click += delegate(object obj, EventArgs args) {
533 ShowParameterForm(node.Sensor);
535 treeContextMenu.MenuItems.Add(item);
537 if (nodeTextBoxText.EditEnabled) {
538 MenuItem item = new MenuItem("Rename");
539 item.Click += delegate(object obj, EventArgs args) {
540 nodeTextBoxText.BeginEdit();
542 treeContextMenu.MenuItems.Add(item);
544 if (node.IsVisible) {
545 MenuItem item = new MenuItem("Hide");
546 item.Click += delegate(object obj, EventArgs args) {
547 node.IsVisible = false;
549 treeContextMenu.MenuItems.Add(item);
551 MenuItem item = new MenuItem("Unhide");
552 item.Click += delegate(object obj, EventArgs args) {
553 node.IsVisible = true;
555 treeContextMenu.MenuItems.Add(item);
557 treeContextMenu.MenuItems.Add(new MenuItem("-"));
559 MenuItem item = new MenuItem("Show in Tray");
560 item.Checked = systemTray.Contains(node.Sensor);
561 item.Click += delegate(object obj, EventArgs args) {
563 systemTray.Remove(node.Sensor);
565 systemTray.Add(node.Sensor, true);
567 treeContextMenu.MenuItems.Add(item);
569 if (gadget != null) {
570 MenuItem item = new MenuItem("Show in Gadget");
571 item.Checked = gadget.Contains(node.Sensor);
572 item.Click += delegate(object obj, EventArgs args) {
574 gadget.Remove(node.Sensor);
576 gadget.Add(node.Sensor);
579 treeContextMenu.MenuItems.Add(item);
581 if (node.Sensor.Control != null) {
582 treeContextMenu.MenuItems.Add(new MenuItem("-"));
583 IControl control = node.Sensor.Control;
584 MenuItem controlItem = new MenuItem("Control");
585 MenuItem defaultItem = new MenuItem("Default");
586 defaultItem.Checked = control.ControlMode == ControlMode.Default;
587 controlItem.MenuItems.Add(defaultItem);
588 defaultItem.Click += delegate(object obj, EventArgs args) {
589 control.SetDefault();
591 MenuItem manualItem = new MenuItem("Manual");
592 controlItem.MenuItems.Add(manualItem);
593 manualItem.Checked = control.ControlMode == ControlMode.Software;
594 for (int i = 0; i <= 100; i += 5) {
595 if (i <= control.MaxSoftwareValue &&
596 i >= control.MinSoftwareValue) {
597 MenuItem item = new MenuItem(i + " %");
598 manualItem.MenuItems.Add(item);
599 item.Checked = control.ControlMode == ControlMode.Software &&
600 Math.Round(control.SoftwareValue) == i;
601 int softwareValue = i;
602 item.Click += delegate(object obj, EventArgs args) {
603 control.SetSoftware(softwareValue);
607 treeContextMenu.MenuItems.Add(controlItem);
610 treeContextMenu.Show(treeView, new Point(m.X, m.Y));
613 HardwareNode hardwareNode = info.Node.Tag as HardwareNode;
614 if (hardwareNode != null && hardwareNode.Hardware != null) {
615 treeContextMenu.MenuItems.Clear();
617 if (nodeTextBoxText.EditEnabled) {
618 MenuItem item = new MenuItem("Rename");
619 item.Click += delegate(object obj, EventArgs args) {
620 nodeTextBoxText.BeginEdit();
622 treeContextMenu.MenuItems.Add(item);
625 treeContextMenu.Show(treeView, new Point(m.X, m.Y));
630 private void saveReportMenuItem_Click(object sender, EventArgs e) {
631 string report = computer.GetReport();
632 if (saveFileDialog.ShowDialog() == DialogResult.OK) {
633 using (TextWriter w = new StreamWriter(saveFileDialog.FileName)) {
639 private void SysTrayHideShow() {
645 protected override void WndProc(ref Message m) {
646 const int WM_SYSCOMMAND = 0x112;
647 const int SC_MINIMIZE = 0xF020;
648 const int SC_CLOSE = 0xF060;
650 if (minimizeToTray.Value &&
651 m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE) {
653 } else if(minimizeOnClose.Value &&
654 m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_CLOSE) {
656 * Apparently the user wants to minimize rather than close
657 * Now we still need to check if we're going to the tray or not
659 * Note: the correct way to do this would be to send out SC_MINIMIZE,
660 * but since the code here is so simple,
661 * that would just be a waste of time.
663 if (minimizeToTray.Value)
666 WindowState = FormWindowState.Minimized;
672 private void hideShowClick(object sender, EventArgs e) {
676 private void ShowParameterForm(ISensor sensor) {
677 ParameterForm form = new ParameterForm();
678 form.Parameters = sensor.Parameters;
679 form.captionLabel.Text = sensor.Name;
683 private void treeView_NodeMouseDoubleClick(object sender,
684 TreeNodeAdvMouseEventArgs e) {
685 SensorNode node = e.Node.Tag as SensorNode;
686 if (node != null && node.Sensor != null &&
687 node.Sensor.Parameters.Length > 0) {
688 ShowParameterForm(node.Sensor);
692 private void celsiusMenuItem_Click(object sender, EventArgs e) {
693 celsiusMenuItem.Checked = true;
694 fahrenheitMenuItem.Checked = false;
695 unitManager.TemperatureUnit = TemperatureUnit.Celsius;
698 private void fahrenheitMenuItem_Click(object sender, EventArgs e) {
699 celsiusMenuItem.Checked = false;
700 fahrenheitMenuItem.Checked = true;
701 unitManager.TemperatureUnit = TemperatureUnit.Fahrenheit;
704 private void sumbitReportMenuItem_Click(object sender, EventArgs e)
706 ReportForm form = new ReportForm();
707 form.Report = computer.GetReport();
711 private void resetMinMaxMenuItem_Click(object sender, EventArgs e) {
712 computer.Accept(new SensorVisitor(delegate(ISensor sensor) {
718 private void MainForm_MoveOrResize(object sender, EventArgs e) {
719 if (WindowState != FormWindowState.Minimized) {
720 settings.SetValue("mainForm.Location.X", Bounds.X);
721 settings.SetValue("mainForm.Location.Y", Bounds.Y);
722 settings.SetValue("mainForm.Width", Bounds.Width);
723 settings.SetValue("mainForm.Height", Bounds.Height);
727 private void resetClick(object sender, EventArgs e) {
728 // disable the fallback MainIcon during reset, otherwise icon visibility
730 systemTray.IsMainIconEnabled = false;
733 // restore the MainIcon setting
734 systemTray.IsMainIconEnabled = minimizeToTray.Value;
737 private void treeView_MouseMove(object sender, MouseEventArgs e) {
738 selectionDragging = selectionDragging &
739 (e.Button & (MouseButtons.Left | MouseButtons.Right)) > 0;
741 if (selectionDragging)
742 treeView.SelectedNode = treeView.GetNodeAt(e.Location);
745 private void treeView_MouseDown(object sender, MouseEventArgs e) {
746 selectionDragging = true;
749 private void treeView_MouseUp(object sender, MouseEventArgs e) {
750 selectionDragging = false;