private void treeView_Click(object sender, EventArgs e) { MouseEventArgs m = e as MouseEventArgs; if (m == null || m.Button != MouseButtons.Right) { return; } NodeControlInfo info = treeView.GetNodeControlInfoAt( new Point(m.X, m.Y) ); treeView.SelectedNode = info.Node; if (info.Node != null) { SensorNode node = info.Node.Tag as SensorNode; if (node != null && node.Sensor != null) { treeContextMenu.MenuItems.Clear(); if (node.Sensor.Parameters.Length > 0) { MenuItem item = new MenuItem("Parameters..."); item.Click += delegate(object obj, EventArgs args) { ShowParameterForm(node.Sensor); }; treeContextMenu.MenuItems.Add(item); } if (nodeTextBoxText.EditEnabled) { MenuItem item = new MenuItem("Rename"); item.Click += delegate(object obj, EventArgs args) { nodeTextBoxText.BeginEdit(); }; treeContextMenu.MenuItems.Add(item); } if (node.IsVisible) { MenuItem item = new MenuItem("Hide"); item.Click += delegate(object obj, EventArgs args) { node.IsVisible = false; }; treeContextMenu.MenuItems.Add(item); } else { MenuItem item = new MenuItem("Unhide"); item.Click += delegate(object obj, EventArgs args) { node.IsVisible = true; }; treeContextMenu.MenuItems.Add(item); } treeContextMenu.MenuItems.Add(new MenuItem("-")); { MenuItem item = new MenuItem("Pen Color..."); item.Click += delegate(object obj, EventArgs args) { ColorDialog dialog = new ColorDialog(); dialog.Color = node.PenColor.GetValueOrDefault(); if (dialog.ShowDialog() == DialogResult.OK) { node.PenColor = dialog.Color; } }; treeContextMenu.MenuItems.Add(item); } { MenuItem item = new MenuItem("Reset Pen Color"); item.Click += delegate(object obj, EventArgs args) { node.PenColor = null; }; treeContextMenu.MenuItems.Add(item); } treeContextMenu.MenuItems.Add(new 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); } }; treeContextMenu.MenuItems.Add(item); } if (gadget != null) { 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); } }; treeContextMenu.MenuItems.Add(item); } if (node.Sensor.Control != null) { treeContextMenu.MenuItems.Add(new MenuItem("-")); IControl control = node.Sensor.Control; MenuItem controlItem = new MenuItem("Control"); MenuItem defaultItem = new MenuItem("Default"); defaultItem.Checked = control.ControlMode == ControlMode.Default; controlItem.MenuItems.Add(defaultItem); defaultItem.Click += delegate(object obj, EventArgs args) { control.SetDefault(); }; MenuItem manualItem = new MenuItem("Manual"); controlItem.MenuItems.Add(manualItem); manualItem.Checked = control.ControlMode == ControlMode.Software; for (int i = 0; i <= 100; i += 5) { if (i <= control.MaxSoftwareValue && i >= control.MinSoftwareValue) { MenuItem item = new MenuItem(i + " %"); item.RadioCheck = true; manualItem.MenuItems.Add(item); item.Checked = control.ControlMode == ControlMode.Software && Math.Round(control.SoftwareValue) == i; int softwareValue = i; item.Click += delegate(object obj, EventArgs args) { control.SetSoftware(softwareValue); }; } } treeContextMenu.MenuItems.Add(controlItem); } treeContextMenu.Show(treeView, new Point(m.X, m.Y)); } HardwareNode hardwareNode = info.Node.Tag as HardwareNode; if (hardwareNode != null && hardwareNode.Hardware != null) { treeContextMenu.MenuItems.Clear(); if (nodeTextBoxText.EditEnabled) { MenuItem item = new MenuItem("Rename"); item.Click += delegate(object obj, EventArgs args) { nodeTextBoxText.BeginEdit(); }; treeContextMenu.MenuItems.Add(item); } treeContextMenu.Show(treeView, new Point(m.X, m.Y)); } } }