0

Started learning WPF and after WinForm I have a lot of questions. For example, here are two of them:

  1. Why, when I set the window size to 300x300 pixels, it is smaller when compiled - it turns out 286x293 pixels (if you set it to 200x200, it will actually be 186x193), it always decreases by 14 and 7 pixels. enter image description here

  2. How can I make the designer display the actual size of the form, and not the enlarged one? enter image description here

Nalik
  • 31
  • 1
  • 2
  • See this: https://stackoverflow.com/questions/67972372/why-are-window-height-and-window-width-not-exact-c-wpf – PaulF Feb 17 '23 at 13:09
  • Thank you. And for the second question, is it possible to display the constructor in real size? – Nalik Feb 17 '23 at 13:23
  • When I set the properties WindowStyle="None" AllowsTransparency="True", the size really becomes correct. But it looks terrible – Nalik Feb 17 '23 at 13:46
  • There is some more detailed info here https://stackoverflow.com/questions/34139450/getwindowrect-returns-a-size-including-invisible-borders - basically your window size really is 300x300 but there is an invisible border around the visible screen. You can see the effect if you move your mouse slowly off of the window - you will see if you move left, right or down that the resize mouse icon remains for a few pixels outside the window. If you move off the top of the window, the mouse icon changes immediately. The only way to stop this behaviour (AFAIK) is in the way described. – PaulF Feb 17 '23 at 14:30
  • Note that the border size is dependent on the DPI of the monitor, so you cannot rely on the 7px border left/right/bottom. You may be able to find code where you can calculate the border size by searching as suggested in the first link & setting the window size in the constructor of your application. If it is critical to your layout, then WPF provides many features to ensure correct sizing & borders around your controls that are preferable to relying on absolute pixel sizes. – PaulF Feb 17 '23 at 14:35

0 Answers0