我有下面的代码。我试着在主屏幕的右边打开窗口,在屏幕的中间。它根本没有移动窗口的起始位置。
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);
发布于 2017-06-02 18:52:19
您应该将代码放在窗口的Load事件中,而且这段代码更易于阅读,我检查了它。
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;
}
https://stackoverflow.com/questions/44335352
复制相似问题