0

I want to open the WPF form on the same screen where it was last closed. I have below code

Closing,

Properties.Settings.Default.WindowTop = this.Top;
      Properties.Settings.Default.WindowLeft = this.Left;
      Properties.Settings.Default.WindowHeight = this.Height;
      Properties.Settings.Default.WindowWidth = this.Width;


      Properties.Settings.Default.WindowState = this.WindowState;

      Properties.Settings.Default.Save();

During initialize

 this.Top = Properties.Settings.Default.WindowTop;
      this.Left = Properties.Settings.Default.WindowLeft;
      this.Height = Properties.Settings.Default.WindowHeight;
      this.Width = Properties.Settings.Default.WindowWidth;
      this.WindowState = Properties.Settings.Default.WindowState;

This solution works except the resolution change. If I change the resolution it will appears incorrectly on screen, it goes out of scope.

So do I use, Setwindowsplacement to achieve this, is it good practice to use interop call with WPF? Please advise.

 private static extern bool SetWindowPlacement(IntPtr hWnd, [In] ref WINDOWPLACEMENT lpwndpl)
Keshavdas M
  • 674
  • 2
  • 7
  • 25
  • What do you mean goes out of scope? Did you change the resolution manually from the desktop or programmatically, and when did you change it? – o_weisman Aug 20 '14 at 13:15
  • yes I change it manually and try to open the application then it restore on correct screen and location but due to resolution change it goes out of scope. Is there any workaround? (I don't want to use setwindowplacement) – Keshavdas M Aug 21 '14 at 04:50
  • Perhaps this can help you: http://stackoverflow.com/questions/8121906/resize-wpf-window-and-contents-depening-on-screen-resolution – o_weisman Aug 21 '14 at 07:33

0 Answers0