ejderuby
ejderuby

Reputation: 735

Window open on the Middle of the Right edge of the screen

I have the following code. I'm trying to make the window open on the right side of the primary screen, midway down the side of the screen. It's not moving the starting location of the window at all.

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);

Upvotes: 0

Views: 555

Answers (1)

pablocity
pablocity

Reputation: 504

You should place your code in Load event of the window, also this code is a bit more readeable, and works as you wanted to, I checked it.

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;
}

Upvotes: 1

Related Questions