From 9805d4cf522fdb854b7cc74963e500709960ec7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=B6ller?= Date: Mon, 16 May 2011 22:04:04 +0000 Subject: [PATCH] Fixed Issue 215. --- GUI/Gadget.cs | 4 ++++ GUI/SensorGadget.cs | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/GUI/Gadget.cs b/GUI/Gadget.cs index f8ff0be..3e601e4 100644 --- a/GUI/Gadget.cs +++ b/GUI/Gadget.cs @@ -176,12 +176,16 @@ namespace OpenHardwareMonitor.GUI { set { if (value != window.Visible) { window.Visible = value; + if (VisibleChanged != null) + VisibleChanged(this, EventArgs.Empty); if (value) Redraw(); } } } + public event EventHandler VisibleChanged; + public void Redraw() { if (!window.Visible) return; diff --git a/GUI/SensorGadget.cs b/GUI/SensorGadget.cs index 0130c82..db9c5b9 100644 --- a/GUI/SensorGadget.cs +++ b/GUI/SensorGadget.cs @@ -201,6 +201,20 @@ namespace OpenHardwareMonitor.GUI { 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(); };