Beispiel #1
0
        private void treeView_Click(object sender, EventArgs e)
        {
            // timer = System.Timers.Timer(DoubleClickTime);
            int clicks = 0;

            int            totalHarddriveCount = 0;
            MouseEventArgs m = e as MouseEventArgs;

            if (m == null || m.Button != MouseButtons.Right) // this means left-mouseclick
            {
                clicks++;



                System.Windows.Forms.MessageBox.Show("Left mouse clicked");
            }

            else
            {
                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("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);
                        }

                        if (hardwareNode.Hardware.HardwareType.ToString() == hardwareNode.HDDType()) // For the HDD's in the system
                        {
                            MenuItem item = new MenuItem("Properties");
                            item.Click += delegate(object obj, EventArgs args)
                            {
                                // Harddrive with Identifier /hdd/7 is at the top of the list and harddrive with identifier /hdd/0 is at the bottom of the list!!!


                                string[]            hddInfo       = { };
                                List <HardwareNode> hardWareNodes = new List <HardwareNode>();
                                foreach (Node n in root.Nodes)
                                {
                                    HardwareNode HN = n as HardwareNode;

                                    if (HN.Hardware.HardwareType.ToString() == hardwareNode.HDDType())
                                    {
                                        totalHarddriveCount++;
                                    }
                                }

                                HDDDialog = new HDDForm();
                                int    driveIndex       = Convert.ToInt32(hardwareNode.Hardware.Identifier.ToString().Replace("/hdd/", ""));
                                string harddriveAddress = @"\\.\PhysicalDrive" + driveIndex;
                                //  IntPtr deviceHandle = smart.OpenDrive(driveIndex);


                                HDDDialog.SelectRequestedHardDisk(hardwareNode.Hardware.Name);
                                HDDDialog.Show();
                            };
                            treeContextMenu.MenuItems.Add(item);
                        }
                        ;

                        if (hardwareNode.Hardware.HardwareType.ToString() == hardwareNode.RAMType()) // For the RAM memory
                        {
                            MenuItem item = new MenuItem("Properties");
                            item.Click += delegate(object obj, EventArgs args)
                            {
                                RAMDialog = new RAMForm();
                                RAMDialog.Show();
                            };
                            treeContextMenu.MenuItems.Add(item);
                        }

                        treeContextMenu.Show(treeView, new Point(m.X, m.Y));
                    }
                }


                return;
            }
        }
Beispiel #2
0
        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.Count > 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));
                }
            }
        }
        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.ActualControlMode == 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.ActualControlMode == 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.ActualControlMode == ControlMode.Software &&
                                               Math.Round(control.SoftwareValue) == i;
                                int softwareValue = i;
                                item.Click += delegate(object obj, EventArgs args) {
                                    control.SetSoftware(softwareValue);
                                };
                            }
                        }
                        MenuItem curveItem = new MenuItem("Manual Curve");
                        controlItem.MenuItems.Add(curveItem);
                        curveItem.Checked = control.ActualControlMode == ControlMode.SoftwareCurve;
                        MenuItem newCurveItem = new MenuItem("New");
                        newCurveItem.Click += delegate(object obj, EventArgs args) {
                            var confirmSensorselect = MessageBox.Show("Select the other sensor after clicking OK.", "New Manual Curve", MessageBoxButtons.OKCancel);
                            if (confirmSensorselect == DialogResult.OK)
                            {
                                // Listen for user click on sensor
                                EventHandler selectorListener = null;
                                selectorListener = (curveselect_sender, curveselect_e) => {
                                    MouseEventArgs curveselect_m = curveselect_e as MouseEventArgs;
                                    if (curveselect_m == null || curveselect_m.Button != MouseButtons.Left)
                                    {
                                        this.treeView.Click -= selectorListener;
                                        return;
                                    }
                                    // Try find sensor user clicked
                                    NodeControlInfo curveselect_info = treeView.GetNodeControlInfoAt(new Point(curveselect_m.X, curveselect_m.Y));
                                    if (curveselect_info.Node != null)
                                    {
                                        SensorNode curveselect_node = curveselect_info.Node.Tag as SensorNode;
                                        if (curveselect_node != null && curveselect_node.Sensor != null)
                                        {
                                            new SensorControlForm(node.Sensor, curveselect_node.Sensor, null).ShowDialog();
                                            return;
                                        }
                                    }

                                    var tryagainSensorselect = MessageBox.Show("Could not find sensor. Try again?", "Manual Curve", MessageBoxButtons.RetryCancel);
                                    if (tryagainSensorselect != DialogResult.Retry)
                                    {
                                        this.treeView.Click -= selectorListener;
                                    }
                                };
                                this.treeView.Click += selectorListener;
                            }
                        };
                        curveItem.MenuItems.Add(newCurveItem);
                        var softwareCurve = node.Sensor.Control.GetSoftwareCurve();
                        if (softwareCurve != null)
                        {
                            // edit curve
                            MenuItem editCurveItem = new MenuItem("Edit");
                            curveItem.MenuItems.Add(editCurveItem);
                            editCurveItem.Click += delegate(object obj, EventArgs args) {
                                new SensorControlForm(node.Sensor, softwareCurve.Sensor, softwareCurve.Points).ShowDialog();
                            };

                            if (control.ActualControlMode != ControlMode.SoftwareCurve)
                            {
                                // enable curve
                                MenuItem enableCurveItem = new MenuItem("Enable");
                                curveItem.MenuItems.Add(enableCurveItem);
                                enableCurveItem.Click += delegate(object obj, EventArgs args) {
                                    node.Sensor.Control.SetSoftwareCurve(softwareCurve.Points, softwareCurve.Sensor);
                                };
                            }
                        }
                        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));
                }
            }
        }
        private void treeView_Click(object sender, EventArgs e)
        {
            var m = e as MouseEventArgs;

            if (m == null || m.Button != MouseButtons.Right)
            {
                return;
            }

            var info = treeView.GetNodeControlInfoAt(
                new Point(m.X, m.Y)
                );

            treeView.SelectedNode = info.Node;
            if (info.Node != null)
            {
                var node = info.Node.Tag as SensorNode;
                if (node != null && node.Sensor != null)
                {
                    treeContextMenu.MenuItems.Clear();
                    if (node.Sensor.Parameters.Length > 0)
                    {
                        var item = new MenuItem("Parameters...");
                        item.Click += delegate { ShowParameterForm(node.Sensor); };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (nodeTextBoxText.EditEnabled)
                    {
                        var item = new MenuItem("Rename");
                        item.Click += delegate { nodeTextBoxText.BeginEdit(); };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (node.IsVisible)
                    {
                        var item = new MenuItem("Hide");
                        item.Click += delegate { node.IsVisible = false; };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    else
                    {
                        var item = new MenuItem("Unhide");
                        item.Click += delegate { node.IsVisible = true; };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    treeContextMenu.MenuItems.Add(new MenuItem("-"));
                    {
                        var item = new MenuItem("Show in Tray");
                        item.Checked = systemTray.Contains(node.Sensor);
                        item.Click  += delegate
                        {
                            if (item.Checked)
                            {
                                systemTray.Remove(node.Sensor);
                            }
                            else
                            {
                                systemTray.Add(node.Sensor, true);
                            }
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (gadget != null)
                    {
                        var item = new MenuItem("Show in Gadget");
                        item.Checked = gadget.Contains(node.Sensor);
                        item.Click  += delegate
                        {
                            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("-"));
                        var control     = node.Sensor.Control;
                        var controlItem = new MenuItem("Control");
                        var defaultItem = new MenuItem("Default");
                        defaultItem.Checked = control.ControlMode == ControlMode.Default;
                        controlItem.MenuItems.Add(defaultItem);
                        defaultItem.Click += delegate { control.SetDefault(); };
                        var manualItem = new MenuItem("Manual");
                        controlItem.MenuItems.Add(manualItem);
                        manualItem.Checked = control.ControlMode == ControlMode.Software;
                        for (var i = 0; i <= 100; i += 5)
                        {
                            if (i <= control.MaxSoftwareValue &&
                                i >= control.MinSoftwareValue)
                            {
                                var item = new MenuItem(i + " %");
                                item.RadioCheck = true;
                                manualItem.MenuItems.Add(item);
                                item.Checked = control.ControlMode == ControlMode.Software &&
                                               Math.Round(control.SoftwareValue) == i;
                                var softwareValue = i;
                                item.Click += delegate { control.SetSoftware(softwareValue); };
                            }
                        }
                        treeContextMenu.MenuItems.Add(controlItem);
                    }

                    treeContextMenu.Show(treeView, new Point(m.X, m.Y));
                }

                var hardwareNode = info.Node.Tag as HardwareNode;
                if (hardwareNode != null && hardwareNode.Hardware != null)
                {
                    treeContextMenu.MenuItems.Clear();

                    if (nodeTextBoxText.EditEnabled)
                    {
                        var item = new MenuItem("Rename");
                        item.Click += delegate { nodeTextBoxText.BeginEdit(); };
                        treeContextMenu.MenuItems.Add(item);
                    }

                    treeContextMenu.Show(treeView, new Point(m.X, m.Y));
                }
            }
        }
Beispiel #5
0
        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("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("控制");
                        MenuItem defaultItem = new MenuItem("默认");
                        defaultItem.Checked = control.ControlMode == ControlMode.Default;
                        controlItem.MenuItems.Add(defaultItem);
                        defaultItem.Click += delegate(object obj, EventArgs args) {
                            control.SetDefault();
                        };
                        MenuItem manualItem = new MenuItem("手动");
                        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 + " %");
                                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);
                        //fan add
                        if (node.Sensor.SensorType.Equals(SensorType.TinyFanControl))
                        {
                            MenuItem controlModeItem = new MenuItem("风扇类型");
                            treeContextMenu.MenuItems.Add(controlModeItem);
                            MenuItem Pin3 = new MenuItem("3针");
                            Pin3.Checked = control.FanMode == FanMode.Pin3;
                            Pin3.Click  += delegate(object obj, EventArgs args){
                                control.SetTheFanMode(FanMode.Pin3);
                            };
                            MenuItem Pin4 = new MenuItem("4针 (PWM)");
                            Pin4.Checked = control.FanMode == FanMode.Pin4;
                            Pin4.Click  += delegate(object obj, EventArgs args){
                                control.SetTheFanMode(FanMode.Pin4);
                            };
                            controlModeItem.MenuItems.Add(Pin3);
                            controlModeItem.MenuItems.Add(Pin4);
                            //add fan-follow. should all fan support this feature. TODO
                            MenuItem controlFanFollow = new MenuItem("自动跟随");
                            treeContextMenu.MenuItems.Add(controlFanFollow);
                            MenuItem followGPU = new MenuItem("显卡");
                            followGPU.Checked = control.FanFollow == FanFollow.GPU;
                            followGPU.Click  += delegate(object obj, EventArgs args)
                            {
                                control.SetTheFanFollow(FanFollow.GPU);
                            };
                            MenuItem followCPU = new MenuItem("CPU");
                            followCPU.Checked = control.FanFollow == FanFollow.CPU;
                            followCPU.Click  += delegate(object obj, EventArgs args)
                            {
                                control.SetTheFanFollow(FanFollow.CPU);
                            };
                            MenuItem followNONE = new MenuItem("关闭");
                            followNONE.Checked = control.FanFollow == FanFollow.NONE;
                            followNONE.Click  += delegate(object obj, EventArgs args)
                            {
                                control.SetTheFanFollow(FanFollow.NONE);
                            };
                            controlFanFollow.MenuItems.Add(followNONE);
                            controlFanFollow.MenuItems.Add(followGPU);
                            controlFanFollow.MenuItems.Add(followCPU);
                        }
                        //fan extend
                    }
                    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));
                }
            }
        }
Beispiel #6
0
        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("参数...");
                        item.Click += delegate(object obj, EventArgs args)
                        {
                            ShowParameterForm(node.Sensor);
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (nodeTextBoxText.EditEnabled)
                    {
                        MenuItem item = new MenuItem("重命名");
                        item.Click += delegate(object obj, EventArgs args)
                        {
                            nodeTextBoxText.BeginEdit();
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    if (node.IsVisible)
                    {
                        MenuItem item = new MenuItem("隐藏");
                        item.Click += delegate(object obj, EventArgs args)
                        {
                            node.IsVisible = false;
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    else
                    {
                        MenuItem item = new MenuItem("取消隐藏");
                        item.Click += delegate(object obj, EventArgs args)
                        {
                            node.IsVisible = true;
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }
                    treeContextMenu.MenuItems.Add(new MenuItem("-"));
                    {
                        MenuItem item = new MenuItem("在托盘中显示");
                        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("显示小工具");
                        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("控制");
                        MenuItem defaultItem = new MenuItem("默认");
                        defaultItem.Checked = control.ControlMode == ControlMode.Default;
                        controlItem.MenuItems.Add(defaultItem);
                        defaultItem.Click += delegate(object obj, EventArgs args)
                        {
                            control.SetDefault();
                        };
                        MenuItem manualItem = new MenuItem("手动");
                        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("重命名");
                        item.Click += delegate(object obj, EventArgs args)
                        {
                            nodeTextBoxText.BeginEdit();
                        };
                        treeContextMenu.MenuItems.Add(item);
                    }

                    treeContextMenu.Show(treeView, new Point(m.X, m.Y));
                }
            }
        }
        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)
                {
                    sensorContextMenu.MenuItems.Clear();
                    if (node.Sensor.Parameters.Length > 0)
                    {
                        MenuItem item = new MenuItem("Parameters...");
                        item.Click += delegate(object obj, EventArgs args) {
                            ShowParameterForm(node.Sensor);
                        };
                        sensorContextMenu.MenuItems.Add(item);
                    }
                    if (nodeTextBoxText.EditEnabled)
                    {
                        MenuItem item = new MenuItem("Rename");
                        item.Click += delegate(object obj, EventArgs args) {
                            nodeTextBoxText.BeginEdit();
                        };
                        sensorContextMenu.MenuItems.Add(item);
                    }
                    if (node.IsVisible)
                    {
                        MenuItem item = new MenuItem("Hide");
                        item.Click += delegate(object obj, EventArgs args) {
                            node.IsVisible = false;
                        };
                        sensorContextMenu.MenuItems.Add(item);
                    }
                    else
                    {
                        MenuItem item = new MenuItem("Unhide");
                        item.Click += delegate(object obj, EventArgs args) {
                            node.IsVisible = true;
                        };
                        sensorContextMenu.MenuItems.Add(item);
                    }
                    sensorContextMenu.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);
                            }
                        };
                        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));
                }
            }
        }