Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF and WIndows 10. Invisible border around windows?

Tags:

c#

wpf

windows-10

When i tried to align my window by side or corner of display, i discovered that there are some kind of padding between edge of screen and edge of my window. I had created new wpf project from template, added only two lines in constructor and got this:



Why it don't fit to the edge of screen? Same problem when i try to put window to the right bottom corner like this:

Rect workArea = SystemParameters.WorkArea;
Left = workArea.Location.X + workArea.Width - Width;
Top = workArea.Location.Y + workArea.Height - Height;

It looks like window has 7px border (just like on win7) but invisible on win10. Also i found that if i set both WindowStyle to WindowStyle.None and ResizeMode to ResizeMode.NoResize, the system places window correctly, but this is not what i need. On win7 same program works as expected.

Of cource i can set Left property to -7, but it is not a solution. How can i properly set window place, so that it will look well on both win7 and win10?

like image 206
BlackOverlord Avatar asked Feb 07 '16 22:02

BlackOverlord


1 Answers

The resizable border on the left/right/bottom is now invisible on Windows 10, and that border is where that gap is. If you put the window in the middle of the screen, and drag your mouse to the left edge of the window, you will see the cursor change to a resizing cursor for 8 pixels further out past the edge of the window. That tells you that the border still exists.

You can get the offests by using a combination of the normal GetWindowRect function and the use of the DwmGetWindowAttribute function, together with the DWMWA_EXTENDED_FRAME_BOUNDS parameter.

like image 165
mikew Avatar answered Nov 05 '22 20:11

mikew