0

I'm using Windows Forms in the .NET Framework. On Windows 7 and previous versions of Windows if I set Form.Left = 0 and Form.Top = 0 then the form is aligned nicely with the left and top edges of my display. But if I do this in Windows 10 the form is placed about 7 pixels in from the left edge while still being aligned with the top edge. If I query From.Top when it is in the state then I can see that it is still set to 0. Form.Padding.Left is also 0.

I assume that the 7 pixel offset from the eleft edge might vary with DPI settings and so on so I don't want to just set Form.Left = -7 to make it align with the left edge.

This seems odd, there must be a simple explanation.

snaddenm
  • 105
  • 7
  • There is. Win10 uses a *visible* border of 1 pixel, the rest is transparent. Move the mouse in the transparent part to see that. – Hans Passant Sep 23 '19 at 14:13
  • @HansPassant, if I move the mouse towards my form from the left then I do indeed see that it changes into a resizing handle when it is about 7 pixels away from the visible edge of the form. If I mouse the mouse downwards towards the top edge of the form then it doesn't change to a resizing handle until I hit the visible edge. It seems that the transparent border is 7 pixels wide on the left, right and bottom but zero pixels with on the top. Is there a way to get the width of the transparent border in code? – snaddenm Sep 23 '19 at 14:25
  • No. Just move it where you want it. The Load event is the correct place to do it, at that point the DPI rescaling and user preferences side-effects are applied. this.Left -= this.PointToScreen(Point.Empty).X - Screen.FromPoint(Point.Empty).WorkingArea.Left - 1; – Hans Passant Sep 23 '19 at 14:31
  • Your mention of the word "transparent" helped me to find other posts which basically asked the same thing, like this one https://stackoverflow.com/questions/49002910/why-does-dwmgetwindowattribute-with-dwmwa-extended-frame-bounds-behave-unexpected. That post shows that calling DwmGetWindowAttribute() to ask for DWMWA_EXTENDED_FRAME_BOUNDS is what I need. When I call that function it returns a RECT object showing that the invisible border is indeed 7 pixels wide and 0 pixels tall. Thanks for your help, I wouldn't have found that information without your input. – snaddenm Sep 23 '19 at 14:40
  • The solution in the previous comment only works when font scaling is set to 100% in Windows 10, it doesn't handle larger fonts. – snaddenm Sep 24 '19 at 06:54

0 Answers0