过去的要求是窗口位于CenterScreen
,但客户最近要求窗口现在稍微偏向其当前位置的右侧。
当前窗口的定义是:
我希望执行以下操作会起作用:
public MyWindow()
{
InitializeComponent();
// change the position after the component is initialized
this.Left = this.Left + this.Width;
}
但是当窗口出现在屏幕上时,它仍然处于相同的位置。
我是否需要将启动位置更改为Manual
并自行定位?如果是这样,我如何让它偏离中心?
最佳答案
处理 Loaded
事件,并将 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;
}
关于c# - WindowStartupLocation ="CenterScreen"时是否可以将窗口位置偏移一个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19725773/