Skip to content

Commit

Permalink
Only use settings if they look valid
Browse files Browse the repository at this point in the history
Top/Left values of 0 probably means uninitialized. We would rather the first run cause the window to pop up in the center of the existing VS window with an appropriate default width and height.
  • Loading branch information
parnic committed Jun 28, 2017
1 parent 66497dd commit 4b58487
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions ListFiles.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,24 +288,27 @@ private void LoadWindowSettings()
{
try
{
var bottomBound = System.Windows.Forms.Screen.AllScreens.Max(s => s.Bounds.Bottom);
var rightBound = System.Windows.Forms.Screen.AllScreens.Max(s => s.Bounds.Right);

// only apply left setting if it is visible on current screen(s)
if (Properties.Settings.Default.Left < rightBound)
if (Properties.Settings.Default.Left > 0 && Properties.Settings.Default.Top > 0)
{
this.Left = Properties.Settings.Default.Left;
}
var bottomBound = System.Windows.Forms.Screen.AllScreens.Max(s => s.Bounds.Bottom);
var rightBound = System.Windows.Forms.Screen.AllScreens.Max(s => s.Bounds.Right);

// only apply top setting if it is visible on current screen(s)
if (Properties.Settings.Default.Top < bottomBound)
{
this.Top = Properties.Settings.Default.Top;
}
// only apply left setting if it is visible on current screen(s)
if (Properties.Settings.Default.Left < rightBound)
{
this.Left = Properties.Settings.Default.Left;
}

this.Width = Properties.Settings.Default.Width;
this.Height = Properties.Settings.Default.Height;
this.WindowState = (WindowState)Properties.Settings.Default.WindowState;
// only apply top setting if it is visible on current screen(s)
if (Properties.Settings.Default.Top < bottomBound)
{
this.Top = Properties.Settings.Default.Top;
}

this.Width = Properties.Settings.Default.Width;
this.Height = Properties.Settings.Default.Height;
this.WindowState = (WindowState)Properties.Settings.Default.WindowState;
}
}
catch (System.Exception)
{
Expand Down

0 comments on commit 4b58487

Please sign in to comment.