0

i have created a userControl with no borders and no padding. I added a button to it with Dock.Fill and also no padding. I assumed the button would be as big as the userControl. And that seems to be right in the designer. But as soon as i start the application the button is actually smaller. The userControl clips the bottom somehow.

Why is that? Any ideas or suggestions?

DesignView

ProgramView

Kind regards

Thanatos
  • 41
  • 5
  • 1
    What do we see ?? – TaW May 07 '21 at 07:30
  • *"the button is actually smaller"* - the theme is applied and the size of text input was increased, resizing `TextBox`. You need to create layout which support themes. Try using `TableLayoutPanel`. – Sinatr May 07 '21 at 07:44
  • @TaW We see that the Button has the same height as the TextBox in Snapshot1 (Designer) But is smaller in Snapshot2 (Runtime) – Thanatos May 07 '21 at 08:39
  • @Sinatr I added a TableLayoutPanel with 1 row/column but the result is still the same – Thanatos May 07 '21 at 08:40
  • I also tried setting the AutoScaleMode of the userControl to "None" Didn't help either – Thanatos May 07 '21 at 08:43
  • I strongly suspect it's layout problem, it would be easier to help after seeing it. You keep saing "user control", perhaps you just need to move layout logic in or out. – Sinatr May 07 '21 at 08:50
  • It's quite *clear*, looking at these images, that your app is not DpiAware. It should be. Start from here: [How to configure an app to run correctly on a machine with a high DPI setting](https://stackoverflow.com/a/13228495/7444103), enhance with [High DPI support in Windows Forms](https://docs.microsoft.com/en-us/dotnet/desktop/winforms/high-dpi-support-in-windows-forms) -- You should decide whether your app scales on Font or Dpi, with some (a lot :) of testing, you can do both. Controls may scale differently in the same context: find a Layout that fits (here, probably vertical-center) – Jimi May 07 '21 at 09:16
  • Note that DpiAwareness support in WinForms is (still) partial/incomplete. As mentioned, some UI elements may *react* differently when scaled. As also noted in comments, use a Container for your Controls - a TableLayoutPanel could do. Test different alignments, use the `Anchors` and/or `Dock` features until you find the correct Layout. -- I suggest you try first to scale on Dpi (`AutoScaleMode = Dpi`, it's more *consistent*). when you have the hang of it, test mixed scaling (Font and Dpi), using appropriate containers and consider the inheritance of these properties. – Jimi May 07 '21 at 09:23
  • Well it's definitely the high resolution monitor. I restarted the studio on my second monitor which is only FullHD and now it appears to be sized correctly. Thanks for the help – Thanatos May 08 '21 at 18:57

0 Answers0