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)