private void InitializePlotForm() { plotForm = new Form { FormBorderStyle = FormBorderStyle.SizableToolWindow, ShowInTaskbar = false, StartPosition = FormStartPosition.Manual }; this.AddOwnedForm(plotForm); plotForm.Bounds = new Rectangle { X = settings.GetValue("plotForm.Location.X", -100000), Y = settings.GetValue("plotForm.Location.Y", 100), Width = settings.GetValue("plotForm.Width", 600), Height = settings.GetValue("plotForm.Height", 400) }; showPlot = new UserOption("plotMenuItem", false, plotMenuItem, settings); plotLocation = new UserRadioGroup("plotLocation", 0, new[] { plotWindowMenuItem, plotBottomMenuItem, plotRightMenuItem }, settings); showPlot.Changed += delegate(object sender, EventArgs e) { if (plotLocation.Value == 0) { if (showPlot.Value && this.Visible) { plotForm.Show(); } else { plotForm.Hide(); } } else { splitContainer.Panel2Collapsed = !showPlot.Value; } treeView.Invalidate(); }; plotLocation.Changed += delegate(object sender, EventArgs e) { switch (plotLocation.Value) { case 0: splitContainer.Panel2.Controls.Clear(); splitContainer.Panel2Collapsed = true; plotForm.Controls.Add(plotPanel); if (showPlot.Value && this.Visible) { plotForm.Show(); } break; case 1: plotForm.Controls.Clear(); plotForm.Hide(); splitContainer.Orientation = Orientation.Horizontal; splitContainer.Panel2.Controls.Add(plotPanel); splitContainer.Panel2Collapsed = !showPlot.Value; break; case 2: plotForm.Controls.Clear(); plotForm.Hide(); splitContainer.Orientation = Orientation.Vertical; splitContainer.Panel2.Controls.Add(plotPanel); splitContainer.Panel2Collapsed = !showPlot.Value; break; } }; plotForm.FormClosing += delegate(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { // just switch off the plotting when the user closes the form if (plotLocation.Value == 0) { showPlot.Value = false; } e.Cancel = true; } }; EventHandler moveOrResizePlotForm = delegate(object sender, EventArgs e) { if (plotForm.WindowState != FormWindowState.Minimized) { settings.SetValue("plotForm.Location.X", plotForm.Bounds.X); settings.SetValue("plotForm.Location.Y", plotForm.Bounds.Y); settings.SetValue("plotForm.Width", plotForm.Bounds.Width); settings.SetValue("plotForm.Height", plotForm.Bounds.Height); } }; plotForm.Move += moveOrResizePlotForm; plotForm.Resize += moveOrResizePlotForm; plotForm.VisibleChanged += delegate(object sender, EventArgs e) { Rectangle bounds = new Rectangle(plotForm.Location, plotForm.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)) { plotForm.Location = new Point( screen.WorkingArea.Width / 2 - bounds.Width / 2, screen.WorkingArea.Height / 2 - bounds.Height / 2); } }; this.VisibleChanged += delegate(object sender, EventArgs e) { if (this.Visible && showPlot.Value && plotLocation.Value == 0) { plotForm.Show(); } else { plotForm.Hide(); } }; }
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; } progressWidthMult = settings.GetValue("sensorGadget.ProgressWidthMult", 1.0f); SetFontSize(settings.GetValue("sensorGadget.FontSize", 7.5f)); percentageDisplayType = (PercentageDisplayType)settings.GetValue("sensorGadget.PercentageDisplayType", 0); 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); MenuItem percentageMenu = new MenuItem("Percentage display"); for (int i = 0; i < 3; i++) { PercentageDisplayType type = (PercentageDisplayType)i; string name; switch (type) { case PercentageDisplayType.ProgressBar: name = "Progress bar"; break; case PercentageDisplayType.Value: name = "Numeric value"; break; case PercentageDisplayType.Both: name = "Both"; break; default: throw new NotImplementedException(); } MenuItem item = new MenuItem(name); item.Checked = percentageDisplayType == type; item.Click += delegate(object sender, EventArgs e) { percentageDisplayType = type; settings.SetValue("sensorGadget.PercentageDisplayType", (int)type); foreach (MenuItem mi in percentageMenu.MenuItems) { mi.Checked = mi == item; } }; percentageMenu.MenuItems.Add(item); } contextMenu.MenuItems.Add(percentageMenu); 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(); }; }
public SensorGadget(IComputer computer, PersistentSettings settings, UnitManager unitManager) { _unitManager = unitManager; _settings = settings; computer.HardwareAdded += HardwareAdded; computer.HardwareRemoved += HardwareRemoved; _darkWhite = new SolidBrush(Color.FromArgb(0xF0, 0xF0, 0xF0)); _stringFormat = new StringFormat { FormatFlags = StringFormatFlags.NoWrap }; _trimStringFormat = new StringFormat { Trimming = StringTrimming.EllipsisCharacter, FormatFlags = StringFormatFlags.NoWrap }; _alignRightStringFormat = new StringFormat { Alignment = StringAlignment.Far, 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 { } } Location = new Point(settings.GetValue("sensorGadget.Location.X", 100), settings.GetValue("sensorGadget.Location.Y", 100)); LocationChanged += delegate { 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)); ContextMenuStrip contextMenu = new ContextMenuStrip(); ToolStripMenuItem hardwareNamesItem = new ToolStripMenuItem("Hardware Names"); contextMenu.Items.Add(hardwareNamesItem); ToolStripMenuItem fontSizeMenu = new ToolStripMenuItem("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(); } ToolStripMenuItem item = new ToolStripMenuItem(name) { Checked = _fontSize == size }; item.Click += delegate { SetFontSize(size); settings.SetValue("sensorGadget.FontSize", size); foreach (ToolStripMenuItem mi in fontSizeMenu.DropDownItems) { mi.Checked = mi == item; } }; fontSizeMenu.DropDownItems.Add(item); } contextMenu.Items.Add(fontSizeMenu); contextMenu.Items.Add(new ToolStripSeparator()); ToolStripMenuItem lockItem = new ToolStripMenuItem("Lock Position and Size"); contextMenu.Items.Add(lockItem); contextMenu.Items.Add(new ToolStripSeparator()); ToolStripMenuItem alwaysOnTopItem = new ToolStripMenuItem("Always on Top"); contextMenu.Items.Add(alwaysOnTopItem); ToolStripMenuItem opacityMenu = new ToolStripMenuItem("Opacity"); contextMenu.Items.Add(opacityMenu); Opacity = (byte)settings.GetValue("sensorGadget.Opacity", 255); for (int i = 0; i < 5; i++) { ToolStripMenuItem item = new ToolStripMenuItem((20 * (i + 1)).ToString() + " %"); byte o = (byte)(51 * (i + 1)); item.Checked = Opacity == o; item.Click += delegate { Opacity = o; settings.SetValue("sensorGadget.Opacity", Opacity); foreach (ToolStripMenuItem mi in opacityMenu.DropDownItems) { mi.Checked = mi == item; } }; opacityMenu.DropDownItems.Add(item); } ContextMenu = contextMenu; _hardwareNames = new UserOption("sensorGadget.Hardwarenames", true, hardwareNamesItem, settings); _hardwareNames.Changed += delegate { Resize(); }; UserOption alwaysOnTop = new UserOption("sensorGadget.AlwaysOnTop", false, alwaysOnTopItem, settings); alwaysOnTop.Changed += delegate { AlwaysOnTop = alwaysOnTop.Value; }; UserOption lockPositionAndSize = new UserOption("sensorGadget.LockPositionAndSize", false, lockItem, settings); lockPositionAndSize.Changed += delegate { 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; } }; SizeChanged += delegate { settings.SetValue("sensorGadget.Width", Size.Width); Redraw(); }; VisibleChanged += delegate { 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 { SendHideShowCommand(); }; }
private void NotificationsForm_FormClosed(object sender, FormClosedEventArgs e) { settings.SetValue(EmailNotificationManager.EmailIdentifier.ToString(), notificationEmailTxtBox.Text); settings.SetValue(GPULoadChecker.ThresholdIdentifier.ToString(), GPULoadNumUpDown.Value.ToString()); settings.SetValue(GPULoadChecker.GraterLessSignIdentifier.ToString(), GPULoadDDL.SelectedIndex); settings.SetValue(GPUTemperatureChecker.ThresholdIdentifier.ToString(), GPUTemperatureNumUpDown.Value.ToString()); settings.SetValue(GPUTemperatureChecker.GraterLessSignIdentifier.ToString(), GPUTemperatureDDL.SelectedIndex); settings.SetValue(CPUTemperatureChecker.ThresholdIdentifier.ToString(), CPUTemperatureNumUpDown.Value.ToString()); settings.SetValue(CPUTemperatureChecker.GraterLessSignIdentifier.ToString(), CPUTemperatureDDL.SelectedIndex); settings.SetValue(CPULoadChecker.ThresholdIdentifier.ToString(), CPULoadNumUpDown.Value.ToString()); settings.SetValue(CPULoadChecker.GraterLessSignIdentifier.ToString(), CPULoadDDL.SelectedIndex); settings.SetValue(MemoryUsageChecker.ThresholdIdentifier.ToString(), MemoryUsageNumUpDown.Value.ToString()); settings.SetValue(MemoryUsageChecker.GraterLessSignIdentifier.ToString(), MemoryUsageDDL.SelectedIndex); }
private void InitializeSplitter() { splitContainer.SplitterDistance = _settings.GetValue("splitContainer.SplitterDistance", 400); splitContainer.SplitterMoved += delegate { _settings.SetValue("splitContainer.SplitterDistance", splitContainer.SplitterDistance); }; }
public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor, PersistentSettings settings, UnitManager unitManager) { _unitManager = unitManager; Sensor = sensor; _notifyIcon = new NotifyIconAdv(); Color defaultColor = Color.White; if (sensor.SensorType == SensorType.Load || sensor.SensorType == SensorType.Control || sensor.SensorType == SensorType.Level) { defaultColor = Color.FromArgb(0xff, 0x70, 0x8c, 0xf1); } Color = settings.GetValue(new Identifier(sensor.Identifier, "traycolor").ToString(), defaultColor); _pen = new Pen(Color.FromArgb(96, Color.Black)); ContextMenu contextMenu = new ContextMenu(); MenuItem hideShowItem = new MenuItem("Hide/Show"); hideShowItem.Click += delegate { sensorSystemTray.SendHideShowCommand(); }; contextMenu.MenuItems.Add(hideShowItem); contextMenu.MenuItems.Add(new MenuItem("-")); MenuItem removeItem = new MenuItem("Remove Sensor"); removeItem.Click += delegate { sensorSystemTray.Remove(Sensor); }; contextMenu.MenuItems.Add(removeItem); MenuItem colorItem = new MenuItem("Change Color..."); colorItem.Click += delegate { ColorDialog dialog = new ColorDialog { Color = Color }; if (dialog.ShowDialog() == DialogResult.OK) { Color = dialog.Color; settings.SetValue(new Identifier(sensor.Identifier, "traycolor").ToString(), Color); } }; contextMenu.MenuItems.Add(colorItem); contextMenu.MenuItems.Add(new MenuItem("-")); MenuItem exitItem = new MenuItem("Exit"); exitItem.Click += delegate { sensorSystemTray.SendExitCommand(); }; contextMenu.MenuItems.Add(exitItem); _notifyIcon.ContextMenu = contextMenu; _notifyIcon.DoubleClick += delegate { sensorSystemTray.SendHideShowCommand(); }; // get the default dpi to create an icon with the correct size float dpiX, dpiY; using (Bitmap b = new Bitmap(1, 1, PixelFormat.Format32bppArgb)) { dpiX = b.HorizontalResolution; dpiY = b.VerticalResolution; } // adjust the size of the icon to current dpi (default is 16x16 at 96 dpi) int width = (int)Math.Round(16 * dpiX / 96); int height = (int)Math.Round(16 * dpiY / 96); // make sure it does never get smaller than 16x16 width = width < 16 ? 16 : width; height = height < 16 ? 16 : height; // adjust the font size to the icon size FontFamily family = SystemFonts.MessageBoxFont.FontFamily; float baseSize; switch (family.Name) { case "Segoe UI": baseSize = 12; break; case "Tahoma": baseSize = 11; break; default: baseSize = 12; break; } _font = new Font(family, baseSize * width / 16.0f, GraphicsUnit.Pixel); _smallFont = new Font(family, 0.75f * baseSize * width / 16.0f, GraphicsUnit.Pixel); _bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); _graphics = Graphics.FromImage(_bitmap); if (Environment.OSVersion.Version.Major > 5) { _graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; _graphics.SmoothingMode = SmoothingMode.HighQuality; } }
public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor, bool balloonTip, PersistentSettings settings) { this.sensor = sensor; this.notifyIcon = new NotifyIcon(); Color defaultColor = Color.Black; if (sensor.SensorType == SensorType.Load || sensor.SensorType == SensorType.Control || sensor.SensorType == SensorType.Level) { defaultColor = Color.FromArgb(0xff, 0x70, 0x8c, 0xf1); } Color = settings.GetValue(new Identifier(sensor.Identifier, "traycolor").ToString(), defaultColor); this.pen = new Pen(Color.FromArgb(96, Color.Black)); this.font = SystemFonts.MessageBoxFont; ContextMenu contextMenu = new ContextMenu(); MenuItem hideShowItem = new MenuItem("Hide/Show"); hideShowItem.Click += delegate(object obj, EventArgs args) { sensorSystemTray.SendHideShowCommand(); }; contextMenu.MenuItems.Add(hideShowItem); contextMenu.MenuItems.Add(new MenuItem("-")); MenuItem removeItem = new MenuItem("Remove Sensor"); removeItem.Click += delegate(object obj, EventArgs args) { sensorSystemTray.Remove(this.sensor); }; contextMenu.MenuItems.Add(removeItem); MenuItem colorItem = new MenuItem("Change Color..."); colorItem.Click += delegate(object obj, EventArgs args) { ColorDialog dialog = new ColorDialog(); dialog.Color = Color; if (dialog.ShowDialog() == DialogResult.OK) { Color = dialog.Color; settings.SetValue(new Identifier(sensor.Identifier, "traycolor").ToString(), Color); } }; contextMenu.MenuItems.Add(colorItem); contextMenu.MenuItems.Add(new MenuItem("-")); MenuItem exitItem = new MenuItem("Exit"); exitItem.Click += delegate(object obj, EventArgs args) { sensorSystemTray.SendExitCommand(); }; contextMenu.MenuItems.Add(exitItem); this.notifyIcon.ContextMenu = contextMenu; this.notifyIcon.DoubleClick += delegate(object obj, EventArgs args) { sensorSystemTray.SendHideShowCommand(); }; // get the default dpi to create an icon with the correct size float dpiX, dpiY; using (Bitmap b = new Bitmap(1, 1, PixelFormat.Format32bppArgb)) { dpiX = b.HorizontalResolution; dpiY = b.VerticalResolution; } // adjust the size of the icon to current dpi (default is 16x16 at 96 dpi) int width = (int)Math.Round(16 * dpiX / 96); int height = (int)Math.Round(16 * dpiY / 96); // make sure it does never get smaller than 16x16 width = width < 16 ? 16: width; height = height < 16 ? 16: height; this.bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); this.graphics = Graphics.FromImage(this.bitmap); if (Environment.OSVersion.Version.Major > 5) { this.graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; this.graphics.SmoothingMode = SmoothingMode.HighQuality; } }
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; 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(); }; MouseDoubleClick += delegate(object obj, MouseEventArgs args) { SendHideShowCommand(); }; }
public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor, bool balloonTip, PersistentSettings settings) { this.sensor = sensor; this.notifyIcon = new NotifyIcon(); Color defaultColor = Color.Black; if (sensor.SensorType == SensorType.Load) { defaultColor = Color.FromArgb(0xff, 0x70, 0x8c, 0xf1); } Color = settings.GetValue(new Identifier(sensor.Identifier, "traycolor").ToString(), defaultColor); this.pen = new Pen(Color.FromArgb(96, Color.Black)); this.font = SystemFonts.MessageBoxFont; ContextMenu contextMenu = new ContextMenu(); MenuItem hideShowItem = new MenuItem("Hide/Show"); hideShowItem.Click += delegate(object obj, EventArgs args) { sensorSystemTray.SendHideShowCommand(); }; contextMenu.MenuItems.Add(hideShowItem); contextMenu.MenuItems.Add(new MenuItem("-")); MenuItem removeItem = new MenuItem("Remove Sensor"); removeItem.Click += delegate(object obj, EventArgs args) { sensorSystemTray.Remove(this.sensor); }; contextMenu.MenuItems.Add(removeItem); MenuItem colorItem = new MenuItem("Change Color..."); colorItem.Click += delegate(object obj, EventArgs args) { ColorDialog dialog = new ColorDialog(); dialog.Color = Color; if (dialog.ShowDialog() == DialogResult.OK) { Color = dialog.Color; settings.SetValue(new Identifier(sensor.Identifier, "traycolor").ToString(), Color); } }; contextMenu.MenuItems.Add(colorItem); contextMenu.MenuItems.Add(new MenuItem("-")); MenuItem exitItem = new MenuItem("Exit"); exitItem.Click += delegate(object obj, EventArgs args) { sensorSystemTray.SendExitCommand(); }; contextMenu.MenuItems.Add(exitItem); this.notifyIcon.ContextMenu = contextMenu; this.notifyIcon.DoubleClick += delegate(object obj, EventArgs args) { sensorSystemTray.SendHideShowCommand(); }; this.bitmap = new Bitmap(16, 16, PixelFormat.Format32bppArgb); this.graphics = Graphics.FromImage(this.bitmap); if (Environment.OSVersion.Version.Major > 5) { this.graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; this.graphics.SmoothingMode = SmoothingMode.HighQuality; } }