1

I am experiencing a very strange issue, and unfortunately it is not very reproducible so I don't have a lot to go on.

I have a page in a WinForms application laid out as per the below. Previously it was just a TableLayoutPanel anchored to the top, bottom, left and right, but now it is a Panel Docked into Fill mode with the same anchored TableLayoutPanel inside:Screenshot of page in Visual Studio

On all computers I have been able to try it on (including with and without Windows' Zoom functions), it displays like the above. However a small number of users experience a screen that looks like the below, with items clipped off screen (this user doesn't have access to the first tab, so it is hidden): enter image description here

Items are clipped off screen and because of the anchoring, resizing doesn't help, they just expand.

I'm unsure how this is triggered but I think it could be something to do with the zoom of the machine being used for Visual Studio vs the zoom of the machine running the application; with that said I've tried running the application on various different zoom levels and can't reproduce the problem on my end. I have also tried adding a panel docked to Fill the area but that doesn't seem to have done much.

Is this something anyone has seen before with WinForms or can provide any suggestions?

Thomas
  • 304
  • 1
  • 2
  • 12
  • Sounds/Looks like a DPI issue: see if https://stackoverflow.com/questions/4075802/creating-a-dpi-aware-application is of any help. – rene Jul 23 '22 at 05:42
  • It looks like you have a .Net Framework application, DpiAwareness is not automatic, you have to opt-in. This is the (base) documentation about [High DPI support in Windows Forms](https://docs.microsoft.com/en-us/dotnet/desktop/winforms/high-dpi-support-in-windows-forms?) (.Net Framework only) -- When your Forms scale (`AutoScaleMode`) to Font instead of Dpi, that's what you get, most of the time. If you want to let the Controls scale to Font, you can *mitigate the problem* making you Forms auto-size to the content, but clearly the visual size of the Forms is not defined by you anymore. – Jimi Jul 23 '22 at 10:39
  • If you target .Net Framework 4.7.2+, use `app.config` to specify the DpiAwareness mode. `PerMonitorV2` is probably better. -- Handling DpiAwareness is not just about changing a setting in the configuration, you have to design your UI for this. Nested auto-sizing containers are your friends (even though it may not seem to be the case at the beginning :) – Jimi Jul 23 '22 at 10:48

1 Answers1

0

Based on the comment from @rene, I looked at the answers on Creating a DPI-Aware Application - the two parts of the answer that resolved it for me were:

  • Disable any scaling on the machine(s) being used for development
  • Run a bulk string-replace across the application's code-base for this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; nand replace it with this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;, and develop all future forms with the AutoScaleMode set to None
Thomas
  • 304
  • 1
  • 2
  • 12