diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj
index 7779aae12..2253f057c 100644
--- a/ILSpy/ILSpy.csproj
+++ b/ILSpy/ILSpy.csproj
@@ -72,6 +72,7 @@
3.5
+
4.0
diff --git a/ILSpy/MainWindow.xaml.cs b/ILSpy/MainWindow.xaml.cs
index 25de2d302..000aa5e6a 100644
--- a/ILSpy/MainWindow.xaml.cs
+++ b/ILSpy/MainWindow.xaml.cs
@@ -31,7 +31,6 @@ using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
-
using ICSharpCode.ILSpy.Debugger;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.TreeNodes;
@@ -78,12 +77,6 @@ namespace ICSharpCode.ILSpy
this.Icon = new BitmapImage(new Uri("pack://application:,,,/ILSpy;component/images/ILSpy.ico"));
this.DataContext = sessionSettings;
- this.Left = sessionSettings.WindowBounds.Left;
- this.Top = sessionSettings.WindowBounds.Top;
- this.Width = sessionSettings.WindowBounds.Width;
- this.Height = sessionSettings.WindowBounds.Height;
- // TODO: validate bounds (maybe a monitor was removed...)
- this.WindowState = sessionSettings.WindowState;
InitializeComponent();
App.CompositionContainer.ComposeParts(this);
@@ -102,6 +95,14 @@ namespace ICSharpCode.ILSpy
this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
}
+ void SetWindowBounds(Rect bounds)
+ {
+ this.Left = bounds.Left;
+ this.Top = bounds.Top;
+ this.Width = bounds.Width;
+ this.Height = bounds.Height;
+ }
+
#region Toolbar extensibility
[ImportMany("ToolbarCommand", typeof(ICommand))]
Lazy[] toolbarCommands = null;
@@ -187,10 +188,26 @@ namespace ICSharpCode.ILSpy
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
- HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
- if (source != null) {
- source.AddHook(WndProc);
+ PresentationSource source = PresentationSource.FromVisual(this);
+ HwndSource hwndSource = source as HwndSource;
+ if (hwndSource != null) {
+ hwndSource.AddHook(WndProc);
}
+ // Validate and Set Window Bounds
+ Rect bounds = Rect.Transform(sessionSettings.WindowBounds, source.CompositionTarget.TransformToDevice);
+ var boundsRect = new System.Drawing.Rectangle((int)bounds.Left, (int)bounds.Top, (int)bounds.Width, (int)bounds.Height);
+ bool boundsOK = false;
+ foreach (var screen in System.Windows.Forms.Screen.AllScreens) {
+ var intersection = System.Drawing.Rectangle.Intersect(boundsRect, screen.WorkingArea);
+ if (intersection.Width > 10 && intersection.Height > 10)
+ boundsOK = true;
+ }
+ if (boundsOK)
+ SetWindowBounds(sessionSettings.WindowBounds);
+ else
+ SetWindowBounds(SessionSettings.DefaultWindowBounds);
+
+ this.WindowState = sessionSettings.WindowState;
}
unsafe IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
diff --git a/ILSpy/SessionSettings.cs b/ILSpy/SessionSettings.cs
index 989538020..433d4bf96 100644
--- a/ILSpy/SessionSettings.cs
+++ b/ILSpy/SessionSettings.cs
@@ -47,7 +47,7 @@ namespace ICSharpCode.ILSpy
}
this.WindowState = FromString((string)doc.Element("WindowState"), WindowState.Normal);
- this.WindowBounds = FromString((string)doc.Element("WindowBounds"), new Rect(10, 10, 750, 550));
+ this.WindowBounds = FromString((string)doc.Element("WindowBounds"), DefaultWindowBounds);
this.SplitterPosition = FromString((string)doc.Element("SplitterPosition"), 0.4);
this.TopPaneSplitterPosition = FromString((string)doc.Element("TopPaneSplitterPosition"), 0.3);
this.BottomPaneSplitterPosition = FromString((string)doc.Element("BottomPaneSplitterPosition"), 0.3);
@@ -69,6 +69,7 @@ namespace ICSharpCode.ILSpy
public WindowState WindowState = WindowState.Normal;
public Rect WindowBounds;
+ internal static Rect DefaultWindowBounds = new Rect(10, 10, 750, 550);
///
/// position of the left/right splitter
///