我想在上次关闭的同一屏幕上打开WPF表单。我有以下代码
截止,
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();
初始化期间
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;
除解决方案更改外,此解决方案有效。如果我更改分辨率,它将在屏幕上显示不正确,则超出范围。
所以我使用Setwindowsplacement来实现这一点,使用WPF的interop调用是不错的做法?请指教。
private static extern bool SetWindowPlacement(IntPtr hWnd, [In] ref WINDOWPLACEMENT lpwndpl)