Permalink
Browse files

Patch from http://community.sharpdevelop.net/forums/t/12899.aspx

  • Loading branch information...
1 parent ce1cba0 commit 5a252208b6ffaccf56e5fee16feaa816cb9a5c5b @PeterForstmeier PeterForstmeier committed Mar 20, 2011
Showing with 37 additions and 0 deletions.
  1. +37 −0 src/Main/Base/Project/Src/Gui/FormLocationHelper.cs
@@ -37,6 +37,42 @@ public static void Apply(Form form, string propertyName, bool isResizable)
public static void ApplyWindow(Window window, string propertyName, bool isResizable)
{
window.WindowStartupLocation = WindowStartupLocation.Manual;
+ Window owner = window.Owner ?? WorkbenchSingleton.MainWindow;
+ Point ownerPos = (owner == null ? new Point(0, 0) : new Point(owner.Left, owner.Top));
+ if (isResizable) {
+ Rect bounds = PropertyService.Get(propertyName, GetDefaultBounds(window));
+ bounds.Offset(ownerPos.X, ownerPos.Y);
+ bounds = Validate(bounds);
+ window.Left = bounds.X;
+ window.Top = bounds.Y;
+ window.Width = bounds.Width;
+ window.Height = bounds.Height;
+ } else {
+ Size size = new Size(window.ActualWidth, window.ActualHeight);
+ Point location = PropertyService.Get(propertyName, GetDefaultLocation(window));
+ location.Offset(ownerPos.X, ownerPos.Y);
+ location = Validate(location, size);
+ window.Left = location.X;
+ window.Top = location.Y;
+ }
+ window.Closing += delegate {
+ owner = window.Owner ?? WorkbenchSingleton.MainWindow;
+ ownerPos = (owner == null ? new Point(0, 0) : new Point(owner.Left, owner.Top));
+ if (isResizable) {
+ if (window.WindowState == System.Windows.WindowState.Normal) {
+ PropertyService.Set(propertyName, new Rect(window.Left, window.Top, window.ActualWidth, window.ActualHeight));
+ }
+ } else {
+ PropertyService.Set(propertyName, new Point(window.Left - ownerPos.X, window.Top - ownerPos.Y));
+
+ }
+ };
+ }
+
+ /*
+ public static void ApplyWindow(Window window, string propertyName, bool isResizable)
+ {
+ window.WindowStartupLocation = WindowStartupLocation.Manual;
if (isResizable) {
Rect bounds = Validate(PropertyService.Get(propertyName, GetDefaultBounds(window)));
window.Left = bounds.X;
@@ -59,6 +95,7 @@ public static void ApplyWindow(Window window, string propertyName, bool isResiza
}
};
}
+ */
public static Rect Validate(Rect bounds)
{

0 comments on commit 5a25220

Please sign in to comment.