if (this.WindowState == WindowState.Normal)
{
Properties.Settings.Default.Top = Top;
Properties.Settings.Default.Left = Left;
Properties.Settings.Default.Height = Height;
Properties.Settings.Default.Width = Width;
}
else
{
Properties.Settings.Default.Top = RestoreBounds.Top;
Properties.Settings.Default.Left = RestoreBounds.Left;
Properties.Settings.Default.Height = RestoreBounds.Height;
Properties.Settings.Default.Width = RestoreBounds.Width;
// Check for WindowState.Maximized or WindowState.Minimized if you
// need to do something different for each case (e.g. store if application
// was Maximized
}
switch (this.WindowState)
{
case WindowState.Maximized:
// don't update the X,Y
break;
case WindowState.Minimized:
// don't update the X,Y
break;
case WindowState.Normal:
// DO update the X,Y
break;
}
2 回答
保存窗口位置时,您需要这样的东西:
重要的是
RestoreBounds
,当窗口最大化或最小化时,您需要它 . 代码可能会被重构,以使其更有效,但你明白了 .我猜你在窗户关闭时更新窗口位置?如果是这种情况,有几种解决方案 .
1)将窗口位置保存在不同的事件上,例如调整窗口大小或移动窗口时 . 2)在保存X和Y位置之前检查窗口是否最小化 .
例: