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 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 SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor, bool balloonTip, PersistentSettings settings, UnitManager unitManager) { this.unitManager = unitManager; Sensor = sensor; notifyIcon = new NotifyIconAdv(); var 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); pen = new Pen(Color.FromArgb(96, Color.Black)); var contextMenu = new ContextMenu(); var hideShowItem = new MenuItem("Hide/Show"); hideShowItem.Click += delegate { sensorSystemTray.SendHideShowCommand(); }; contextMenu.MenuItems.Add(hideShowItem); contextMenu.MenuItems.Add(new MenuItem("-")); var removeItem = new MenuItem("Remove Sensor"); removeItem.Click += delegate { sensorSystemTray.Remove(this.Sensor); }; contextMenu.MenuItems.Add(removeItem); var colorItem = new MenuItem("Change Color..."); colorItem.Click += delegate { var 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("-")); var 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 (var 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) var width = (int)Math.Round(16 * dpiX / 96); var 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 var 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) { this.sensor = sensor; this.notifyIcon = new NotifyIcon(); Color defaultColor = Color.Black; if (sensor.SensorType == SensorType.Load) { defaultColor = Color.FromArgb(0xff, 0x70, 0x8c, 0xf1); } Color = Config.Get(new Identifier(sensor.Identifier, "traycolor").ToString(), defaultColor); this.pen = new Pen(Color.FromArgb(96, Color.Black)); this.font = SystemFonts.MessageBoxFont; ContextMenuStrip contextMenuStrip = new ContextMenuStrip(); ToolStripMenuItem hideShowItem = new ToolStripMenuItem("Hide/Show"); hideShowItem.Click += delegate(object obj, EventArgs args) { sensorSystemTray.SendHideShowCommand(); }; contextMenuStrip.Items.Add(hideShowItem); contextMenuStrip.Items.Add(new ToolStripSeparator()); ToolStripMenuItem removeItem = new ToolStripMenuItem("Remove Sensor"); removeItem.Click += delegate(object obj, EventArgs args) { sensorSystemTray.Remove(this.sensor); }; contextMenuStrip.Items.Add(removeItem); ToolStripMenuItem colorItem = new ToolStripMenuItem("Change Color..."); colorItem.Click += delegate(object obj, EventArgs args) { ColorDialog dialog = new ColorDialog(); dialog.Color = Color; if (dialog.ShowDialog() == DialogResult.OK) { Color = dialog.Color; Config.Set(new Identifier(sensor.Identifier, "traycolor").ToString(), Color); } }; contextMenuStrip.Items.Add(colorItem); contextMenuStrip.Items.Add(new ToolStripSeparator()); ToolStripMenuItem exitItem = new ToolStripMenuItem("Exit"); exitItem.Click += delegate(object obj, EventArgs args) { sensorSystemTray.SendExitCommand(); }; contextMenuStrip.Items.Add(exitItem); this.notifyIcon.ContextMenuStrip = contextMenuStrip; 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; } }