# HG changeset patch # User moel.mich # Date 1305583444 0 # Node ID d4798e7f438898cc21d66856a89a2b1f4c085063 # Parent a35a89a35532672f2d89ac7a5336459f7cc647d5 Fixed Issue 215. diff -r a35a89a35532 -r d4798e7f4388 GUI/Gadget.cs --- a/GUI/Gadget.cs Sun May 15 21:43:40 2011 +0000 +++ b/GUI/Gadget.cs Mon May 16 22:04:04 2011 +0000 @@ -176,12 +176,16 @@ 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 -r a35a89a35532 -r d4798e7f4388 GUI/SensorGadget.cs --- a/GUI/SensorGadget.cs Sun May 15 21:43:40 2011 +0000 +++ b/GUI/SensorGadget.cs Mon May 16 22:04:04 2011 +0000 @@ -201,6 +201,20 @@ 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(); };