Tono Nam
Tono Nam

Reputation: 36048

Set custom window position on wpf

I think there is a bug with the Window.Width and Window.Height of wpf. I need my window to cover my entire desktop (there are two monitors) but first let me show you why I think there is a bug.

First let me show you the resolution of my monitors: (both have the same resolution)

enter image description here

this is the window on visual studio that I am working with

enter image description here

I don't know if you guys know AutoIt but it is a nice program to automate simple stuff. so if I want to resize my MainWindow to cover all the space in my first monitor (same thing as if I where maximizing a window) I will execute this method on autoit: enter image description here

and when I execute that code my window that I am creating in visual studio extends and it appears exactly as if it where to be maximized.

enter image description here

so far the coordinates seem to be working.

now when I do the same thing with c# on wpf:


    public static void setWindowSize(System.Windows.Window w)
    {
        w.Left = 0;
        w.Top =0;
        w.Width = 1920;
        w.Height = 1079;
    }

The parameter w will be the MainWindow. When I execute that take a look how the window get's resized: enter image description here

I placed the older image next to it so that you guys can compare it. Why are the dimensions not the same? I belive that the Window.Width and Window.Height properties do not work correctly. or what am I doing wrong?

Upvotes: 2

Views: 1498

Answers (2)

Haris Hasan
Haris Hasan

Reputation: 30097

If you want to cover your main monitor then

Width = SystemParameters.PrimaryScreenWidth, Height = SystemParameters.PrimaryScreenHeight

if you want to cover both monitors

Width = SystemParameters.VirtualScreenWidth, Height = SystemParameters.VirtualScreenHeight

Upvotes: 4

Learner
Learner

Reputation: 1542

try out this

Width = SystemParameters.PrimaryScreenWidth, Height = SystemParameters.PrimaryScreenHeight,

Upvotes: 1

Related Questions