Window 在屏幕右边缘的中间打开
Window open on the Middle of the Right edge of the screen
我有以下代码。我试图让 window 在主屏幕的右侧打开,在屏幕一侧的中间位置。它根本没有移动 window 的起始位置。
int screenWidth = (int)System.Windows.SystemParameters.PrimaryScreenWidth;
int screenHeight = (int)System.Windows.SystemParameters.PrimaryScreenHeight;
cd.Top = (screenHeight / 2) - (cd.Height / 2);
cd.Left = screenWidth - (cd.Width + 4);
您应该将您的代码放在 Load 事件 window 中,而且这段代码更具可读性,并按照您的意愿工作,我检查过了。
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var desktopWorkingArea = System.Windows.SystemParameters.WorkArea;
this.Left = desktopWorkingArea.Right - this.Width;
this.Top = desktopWorkingArea.Top + this.Height;
}
我有以下代码。我试图让 window 在主屏幕的右侧打开,在屏幕一侧的中间位置。它根本没有移动 window 的起始位置。
int screenWidth = (int)System.Windows.SystemParameters.PrimaryScreenWidth;
int screenHeight = (int)System.Windows.SystemParameters.PrimaryScreenHeight;
cd.Top = (screenHeight / 2) - (cd.Height / 2);
cd.Left = screenWidth - (cd.Width + 4);
您应该将您的代码放在 Load 事件 window 中,而且这段代码更具可读性,并按照您的意愿工作,我检查过了。
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var desktopWorkingArea = System.Windows.SystemParameters.WorkArea;
this.Left = desktopWorkingArea.Right - this.Width;
this.Top = desktopWorkingArea.Top + this.Height;
}