C# 当WindowsStartUpLocation=";时,是否可以将窗口位置偏移一个值;中心屏幕;?
以前的要求是窗口为C# 当WindowsStartUpLocation=";时,是否可以将窗口位置偏移一个值;中心屏幕;?,c#,wpf,C#,Wpf,以前的要求是窗口为CenterScreen,但客户最近要求窗口现在稍微位于其当前位置的右侧 窗口的当前定义为: 我希望做以下工作会奏效: public MyWindow() { InitializeComponent(); // change the position after the component is initialized this.Left = this.Left + this.Width; } 但当窗
CenterScreen
,但客户最近要求窗口现在稍微位于其当前位置的右侧
窗口的当前定义为:
我希望做以下工作会奏效:
public MyWindow()
{
InitializeComponent();
// change the position after the component is initialized
this.Left = this.Left + this.Width;
}
但当窗口出现在屏幕上时,它仍然处于相同的位置
我是否需要将启动位置更改为
手动
并自行定位?如果是这样,我如何使其偏离中心?处理加载的事件,并放置this.Left=this.Left+this.Width代码>那里:
public MyWindow()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MyWindow_Loaded);
}
void MyWindow_Loaded(object sender, RoutedEventArgs e)
{
this.Left = this.Left + this.Width;
}
在设计中
右键单击窗口
选择属性。
在“属性”侧面板中查找“StartPosition
”
将其值设置为“CenterScreen
”
或
您可以在窗口的InitializeComponent()中尝试以下代码
this.StartPosition=FormStartPosition.CenterScreen;
或
如果是弹出窗口,请尝试使用以下代码
this.StartPosition=FormStartPosition.CenterParent;
或
如果是应用程序启动的窗口,则使用以下设置
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen