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