From e8909c4f188d6446e9960b5afc23f72dc85c5dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=B6ller?= Date: Tue, 7 Sep 2010 18:32:37 +0000 Subject: [PATCH] Fixed a few closure variables. The local variables used in the closure can not be shared between closures if their values should be different. --- GUI/MainForm.cs | 44 +++++++++++++++++++++++--------------------- GUI/SensorGadget.cs | 5 ++--- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index cf9d7bb..a6083d1 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -394,27 +394,29 @@ namespace OpenHardwareMonitor.GUI { sensorContextMenu.MenuItems.Add(item); } sensorContextMenu.MenuItems.Add(new MenuItem("-")); - - MenuItem menuItem = new MenuItem("Show in Tray"); - menuItem.Checked = systemTray.Contains(node.Sensor); - menuItem.Click += delegate(object obj, EventArgs args) { - if (menuItem.Checked) - systemTray.Remove(node.Sensor); - else - systemTray.Add(node.Sensor, true); - }; - sensorContextMenu.MenuItems.Add(menuItem); - - menuItem = new MenuItem("Show in Gadget"); - menuItem.Checked = gadget.Contains(node.Sensor); - menuItem.Click += delegate(object obj, EventArgs args) { - if (menuItem.Checked) { - gadget.Remove(node.Sensor); - } else { - gadget.Add(node.Sensor); - } - }; - sensorContextMenu.MenuItems.Add(menuItem); + { + MenuItem item = new MenuItem("Show in Tray"); + item.Checked = systemTray.Contains(node.Sensor); + item.Click += delegate(object obj, EventArgs args) { + if (item.Checked) + systemTray.Remove(node.Sensor); + else + systemTray.Add(node.Sensor, true); + }; + sensorContextMenu.MenuItems.Add(item); + } + { + MenuItem item = new MenuItem("Show in Gadget"); + item.Checked = gadget.Contains(node.Sensor); + item.Click += delegate(object obj, EventArgs args) { + if (item.Checked) { + gadget.Remove(node.Sensor); + } else { + gadget.Add(node.Sensor); + } + }; + sensorContextMenu.MenuItems.Add(item); + } sensorContextMenu.Show(treeView, new Point(m.X, m.Y)); } diff --git a/GUI/SensorGadget.cs b/GUI/SensorGadget.cs index dc535e7..1a16dfc 100644 --- a/GUI/SensorGadget.cs +++ b/GUI/SensorGadget.cs @@ -100,13 +100,12 @@ namespace OpenHardwareMonitor.GUI { for (int i = 0; i < 5; i++) { MenuItem item = new MenuItem((20 * (i + 1)).ToString() + " %"); byte o = (byte)(51 * (i + 1)); - item.Tag = o; item.Checked = Opacity == o; item.Click += delegate(object sender, EventArgs e) { - Opacity = (byte)item.Tag; + Opacity = o; settings.SetValue("sensorGadget.Opacity", Opacity); foreach (MenuItem mi in opacityMenu.MenuItems) - mi.Checked = (byte)mi.Tag == Opacity; + mi.Checked = mi == item; }; opacityMenu.MenuItems.Add(item); }