The requirement used to be that the window is CenterScreen
but the client has recently asked that the window is now slightly to the right of its current position.
The current definition of the window is:
I was hoping that doing the following would work:
public MyWindow()
{
InitializeComponent();
// change the position after the component is initialized
this.Left = this.Left + this.Width;
}
But the window is still in the same position when it appears on screen.
Do I need to change the startup location to Manual
and position it myself? If so, how do I get it offset from the center?
Setting the WindowStartupLocation property to CenterScreen causes a window to be positioned in the center of the screen that contains the mouse cursor. Setting the WindowStartupLocation property to CenterOwner causes a window to be positioned in the center of its owner window (see Window.Owner), if specified.
A WindowStartupLocation value that specifies the top/left position of a window when first shown. The default is Manual. Setting the WindowStartupLocation property to Manual causes a window to be positioned according to its Left and Top property values. If either the Left or Top properties aren't specified, their values are determined by Windows.
System. Windows Window. Window Startup Location Property System. Windows Gets or sets the position of the window when first shown. A WindowStartupLocation value that specifies the top/left position of a window when first shown. The default is Manual.
You cannot set or get the value of this property when a window is hosted in a browser. Gets or sets a value that indicates whether a window will automatically size itself to fit the size of its content. Occurs when a mouse button is clicked two or more times.
Handle Loaded
event, and put this.Left = this.Left + this.Width;
there:
public MyWindow()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MyWindow_Loaded);
}
void MyWindow_Loaded(object sender, RoutedEventArgs e)
{
this.Left = this.Left + this.Width;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With