示例#1
0
        private ContextMenu CreateMenu()
        {
            ContextMenu menu = new ContextMenu();

            MenuItem stackedAxesMenuItem = new MenuItem("Stacked Axes");

            stackedAxes = new UserOption("stackedAxes", true,
                                         stackedAxesMenuItem, settings);
            stackedAxes.Changed += (sender, e) => {
                UpdateAxesPosition();
                InvalidatePlot();
            };
            menu.MenuItems.Add(stackedAxesMenuItem);

            MenuItem timeWindow = new MenuItem("Time Window");

            MenuItem[] timeWindowMenuItems =
            { new MenuItem("Auto",
                           (s,                                                            e) =>  { timeAxis.Zoom(0, double.NaN); InvalidatePlot();    }),
              new MenuItem("5 min",
                           (s,                                                                e) =>  { timeAxis.Zoom(0,        5 * 60); InvalidatePlot(); }),
              new MenuItem("10 min",
                           (s,                                                                e) =>  { timeAxis.Zoom(0,       10 * 60); InvalidatePlot(); }),
              new MenuItem("20 min",
                           (s,                                                                e) =>  { timeAxis.Zoom(0,       20 * 60); InvalidatePlot(); }),
              new MenuItem("30 min",
                           (s,                                                                e) =>  { timeAxis.Zoom(0,       30 * 60); InvalidatePlot(); }),
              new MenuItem("45 min",
                           (s,                                                                e) =>  { timeAxis.Zoom(0,       45 * 60); InvalidatePlot(); }),
              new MenuItem("1 h",
                           (s,                                                                e) =>  { timeAxis.Zoom(0,       60 * 60); InvalidatePlot(); }),
              new MenuItem("1.5 h",
                           (s,                                                                e) =>  { timeAxis.Zoom(0, 1.5 * 60 * 60); InvalidatePlot(); }),
              new MenuItem("2 h",
                           (s,                                                                e) =>  { timeAxis.Zoom(0,   2 * 60 * 60); InvalidatePlot(); }),
              new MenuItem("3 h",
                           (s,                                                                e) =>  { timeAxis.Zoom(0,   3 * 60 * 60); InvalidatePlot(); }),
              new MenuItem("6 h",
                           (s,                                                                e) =>  { timeAxis.Zoom(0,   6 * 60 * 60); InvalidatePlot(); }),
              new MenuItem("12 h",
                           (s,                                                                e) =>  { timeAxis.Zoom(0,  12 * 60 * 60); InvalidatePlot(); }),
              new MenuItem("24 h",
                           (s,                                                                e) =>  { timeAxis.Zoom(0,  24 * 60 * 60); InvalidatePlot(); }) };
            foreach (MenuItem mi in timeWindowMenuItems)
            {
                timeWindow.MenuItems.Add(mi);
            }
            menu.MenuItems.Add(timeWindow);

            return(menu);
        }
示例#2
0
        public SensorGadget(IComputer computer, PersistentSettings settings,
                            UnitManager unitManager)
        {
            this.unitManager          = unitManager;
            this.settings             = settings;
            computer.HardwareAdded   += new HardwareEventHandler(HardwareAdded);
            computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);

            this.darkWhite = new SolidBrush(Color.FromArgb(0xF0, 0xF0, 0xF0));

            this.stringFormat             = new StringFormat();
            this.stringFormat.FormatFlags = StringFormatFlags.NoWrap;

            this.trimStringFormat             = new StringFormat();
            this.trimStringFormat.Trimming    = StringTrimming.EllipsisCharacter;
            this.trimStringFormat.FormatFlags = StringFormatFlags.NoWrap;

            this.alignRightStringFormat             = new StringFormat();
            this.alignRightStringFormat.Alignment   = StringAlignment.Far;
            this.alignRightStringFormat.FormatFlags = StringFormatFlags.NoWrap;

            if (File.Exists("gadget_background.png"))
            {
                try {
                    Image newBack = new Bitmap("gadget_background.png");
                    back.Dispose();
                    back = newBack;
                } catch { }
            }

            if (File.Exists("gadget_image.png"))
            {
                try {
                    image = new Bitmap("gadget_image.png");
                } catch {}
            }

            if (File.Exists("gadget_foreground.png"))
            {
                try {
                    fore = new Bitmap("gadget_foreground.png");
                } catch { }
            }

            if (File.Exists("gadget_bar_background.png"))
            {
                try {
                    Image newBarBack = new Bitmap("gadget_bar_background.png");
                    barBack.Dispose();
                    barBack = newBarBack;
                } catch { }
            }

            if (File.Exists("gadget_bar_foreground.png"))
            {
                try {
                    Image newBarColor = new Bitmap("gadget_bar_foreground.png");
                    barFore.Dispose();
                    barFore = newBarColor;
                } catch { }
            }

            this.Location = new Point(
                settings.GetValue("sensorGadget.Location.X", 100),
                settings.GetValue("sensorGadget.Location.Y", 100));
            LocationChanged += delegate(object sender, EventArgs e) {
                settings.SetValue("sensorGadget.Location.X", Location.X);
                settings.SetValue("sensorGadget.Location.Y", Location.Y);
            };

            // get the custom to default dpi ratio
            using (Bitmap b = new Bitmap(1, 1)) {
                scale = b.HorizontalResolution / 96.0f;
            }

            SetFontSize(settings.GetValue("sensorGadget.FontSize", 7.5f));
            Resize(settings.GetValue("sensorGadget.Width", Size.Width));

            ContextMenu contextMenu       = new ContextMenu();
            MenuItem    hardwareNamesItem = new MenuItem("Hardware Names");

            contextMenu.MenuItems.Add(hardwareNamesItem);
            MenuItem fontSizeMenu = new MenuItem("Font Size");

            for (int i = 0; i < 4; i++)
            {
                float  size;
                string name;
                switch (i)
                {
                case 0: size = 6.5f; name = "Small"; break;

                case 1: size = 7.5f; name = "Medium"; break;

                case 2: size = 9f; name = "Large"; break;

                case 3: size = 11f; name = "Very Large"; break;

                default: throw new NotImplementedException();
                }
                MenuItem item = new MenuItem(name);
                item.Checked = fontSize == size;
                item.Click  += delegate(object sender, EventArgs e) {
                    SetFontSize(size);
                    settings.SetValue("sensorGadget.FontSize", size);
                    foreach (MenuItem mi in fontSizeMenu.MenuItems)
                    {
                        mi.Checked = mi == item;
                    }
                };
                fontSizeMenu.MenuItems.Add(item);
            }
            contextMenu.MenuItems.Add(fontSizeMenu);
            contextMenu.MenuItems.Add(new MenuItem("-"));
            MenuItem lockItem = new MenuItem("Lock Position and Size");

            contextMenu.MenuItems.Add(lockItem);
            contextMenu.MenuItems.Add(new MenuItem("-"));
            MenuItem alwaysOnTopItem = new MenuItem("Always on Top");

            contextMenu.MenuItems.Add(alwaysOnTopItem);
            MenuItem opacityMenu = new MenuItem("Opacity");

            contextMenu.MenuItems.Add(opacityMenu);
            Opacity = (byte)settings.GetValue("sensorGadget.Opacity", 255);
            for (int i = 0; i < 5; i++)
            {
                MenuItem item = new MenuItem((20 * (i + 1)).ToString() + " %");
                byte     o    = (byte)(51 * (i + 1));
                item.Checked = Opacity == o;
                item.Click  += delegate(object sender, EventArgs e) {
                    Opacity = o;
                    settings.SetValue("sensorGadget.Opacity", Opacity);
                    foreach (MenuItem mi in opacityMenu.MenuItems)
                    {
                        mi.Checked = mi == item;
                    }
                };
                opacityMenu.MenuItems.Add(item);
            }
            this.ContextMenu = contextMenu;

            hardwareNames = new UserOption("sensorGadget.Hardwarenames", true,
                                           hardwareNamesItem, settings);
            hardwareNames.Changed += delegate(object sender, EventArgs e) {
                Resize();
            };

            alwaysOnTop = new UserOption("sensorGadget.AlwaysOnTop", false,
                                         alwaysOnTopItem, settings);
            alwaysOnTop.Changed += delegate(object sender, EventArgs e) {
                this.AlwaysOnTop = alwaysOnTop.Value;
            };
            lockPositionAndSize = new UserOption("sensorGadget.LockPositionAndSize",
                                                 false, lockItem, settings);
            lockPositionAndSize.Changed += delegate(object sender, EventArgs e) {
                this.LockPositionAndSize = lockPositionAndSize.Value;
            };

            HitTest += delegate(object sender, HitTestEventArgs e) {
                if (lockPositionAndSize.Value)
                {
                    return;
                }

                if (e.Location.X < leftBorder)
                {
                    e.HitResult = HitResult.Left;
                    return;
                }
                if (e.Location.X > Size.Width - 1 - rightBorder)
                {
                    e.HitResult = HitResult.Right;
                    return;
                }
            };

            SizeChanged += delegate(object sender, EventArgs e) {
                settings.SetValue("sensorGadget.Width", Size.Width);
                Redraw();
            };

            VisibleChanged += delegate(object sender, EventArgs e) {
                Rectangle bounds       = new Rectangle(Location, Size);
                Screen    screen       = Screen.FromRectangle(bounds);
                Rectangle intersection =
                    Rectangle.Intersect(screen.WorkingArea, bounds);
                if (intersection.Width < Math.Min(16, bounds.Width) ||
                    intersection.Height < Math.Min(16, bounds.Height))
                {
                    Location = new Point(
                        screen.WorkingArea.Width / 2 - bounds.Width / 2,
                        screen.WorkingArea.Height / 2 - bounds.Height / 2);
                }
            };

            MouseDoubleClick += delegate(object obj, MouseEventArgs args) {
                SendHideShowCommand();
            };
        }