【发布时间】:2017-06-02 18:31:00
【问题描述】:
我有以下代码。我试图让窗口在主屏幕的右侧打开,在屏幕侧面的中间。它根本没有移动窗口的起始位置。
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);
【问题讨论】:
-
据我了解,“cd”是您的 Window 实例?如果您将代码放在 MainWindow 类中,只需使用 this.Top 和 this.Left 而不是创建实例