@@ -44,6 +44,11 @@ public ListFiles(IEnumerable<ProjectItemWrapper> inItems)
4444 }
4545 }
4646
47+ protected void Window_SourceInitialized ( object sender , System . EventArgs e )
48+ {
49+ LoadWindowSettings ( ) ;
50+ }
51+
4752 private void FilterProjectItems ( object sender , FilterEventArgs e )
4853 {
4954 e . Accepted = true ;
@@ -137,6 +142,11 @@ private void OpenSelectedFiles(bool bInSolutionExplorer)
137142 Close ( ) ;
138143 }
139144
145+ private void Window_Closing ( object sender , System . ComponentModel . CancelEventArgs e )
146+ {
147+ SaveWindowSettings ( ) ;
148+ }
149+
140150 private void txtFilter_KeyDown ( object sender , KeyEventArgs e )
141151 {
142152 if ( lstFiles . Items . Count > 0 )
@@ -270,5 +280,49 @@ private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
270280 }
271281 }
272282 }
283+
284+ /// <summary>
285+ /// Restores the window's previous size and position
286+ /// </summary>
287+ private void LoadWindowSettings ( )
288+ {
289+ try
290+ {
291+ var bottomBound = System . Windows . Forms . Screen . AllScreens . Max ( s => s . Bounds . Bottom ) ;
292+ var rightBound = System . Windows . Forms . Screen . AllScreens . Max ( s => s . Bounds . Right ) ;
293+
294+ // only apply left setting if it is visible on current screen(s)
295+ if ( Properties . Settings . Default . Left < rightBound )
296+ {
297+ this . Left = Properties . Settings . Default . Left ;
298+ }
299+
300+ // only apply top setting if it is visible on current screen(s)
301+ if ( Properties . Settings . Default . Top < bottomBound )
302+ {
303+ this . Top = Properties . Settings . Default . Top ;
304+ }
305+
306+ this . Width = Properties . Settings . Default . Width ;
307+ this . Height = Properties . Settings . Default . Height ;
308+ this . WindowState = ( WindowState ) Properties . Settings . Default . WindowState ;
309+ }
310+ catch ( System . Exception ex )
311+ {
312+ // swallow exception if settings fail to load
313+ }
314+ }
315+
316+ /// <summary>
317+ /// Saves the window's current size and position
318+ /// </summary>
319+ private void SaveWindowSettings ( )
320+ {
321+ Properties . Settings . Default . Width = RestoreBounds . Width ;
322+ Properties . Settings . Default . Height = RestoreBounds . Height ;
323+ Properties . Settings . Default . Top = RestoreBounds . Top ;
324+ Properties . Settings . Default . Left = RestoreBounds . Left ;
325+ Properties . Settings . Default . WindowState = ( int ) this . WindowState ;
326+ }
273327 }
274328}
0 commit comments