2

I am writing this application and it has a size of (800 X 400). The problem is, it resizes when I run it on different monitor resolutions and all the objects get bigger. Is there a way to fix its size for all monitor resolution without maximizing?

Hotkey
  • 421
  • 5
  • 11
  • [How to configure an app to run correctly on a machine with a high DPI setting (e.g. 150%)?](https://stackoverflow.com/a/13228495/7444103) -- [High DPI support in Windows Forms](https://learn.microsoft.com/en-us/dotnet/framework/winforms/high-dpi-support-in-windows-forms#configuring-your-windows-forms-app-for-high-dpi-support) -- See the notes here about [Display identification and positioning](https://stackoverflow.com/a/53026765/7444103) – Jimi Jul 27 '19 at 12:19
  • It could not fix the problem @Jimi –  Jul 27 '19 at 12:52
  • 1
    Have you set the Forms' `AutoScaleMode` to `Dpi`? – Jimi Jul 27 '19 at 13:01
  • Yes, i have already set that. –  Jul 27 '19 at 16:35
  • Well, your implementation is lacking in some parts, then. But noboby can see what you have modified. Remember to also set the Font of the Controls explicitly, don't let them inherit it (unless you have explicitly planned for that, too). – Jimi Jul 27 '19 at 16:46

1 Answers1

2

In general, if your form is defined with a fixed size of (800 x 400) then it will generally appear larger on the same screen if you change the resolution to say (800 x 600).

The screen resolution defines how many pixels make up the view port. changing to a high resolution will make all apps, not just yours appear smaller. Changing to a low resolution can make all apps, again not just yours appear larger.

Changing the screen resolution is changing the DPI

Windows and WinForms do provide some mechanisms for scaling your app so the interface can be more proportional on different screens, but it can be a bit more hit and miss to take advantage of in WinForms compared to other technologies like WPF/UWP, especially if you have an older application or code base.

If the scaling is not what you expect, first check that the users have turned scaling in their display settings back to 100%, many laptops and tablets have the set to 125% OOTB. When you have not correctly defined your interfaces to take advantage of font scaling it can look a bit funky.

Setting windows font scaling back to 100% means your app will only have to contend with DPI scaling issues rather than both font and DPI scaling that windows might impose.

font scaling in the display settings, in windows 10 looks like this: Change Font scaling in Windows 10

Have a read over: Automatic scaling in Windows Forms

The key to getting it right is that all forms and controls in your app must be configured to use DPI based scaling OR Font based scaling. When the two concepts are confused the UI can look like a mess as some elements will resize and others may not.

This scaling behaviour is defined in the form as the AutoScaleMode: AutoScaleMode in WinForms - This defaults to Font in new apps.

Many 3rd part components however may be set to DPI mode, especially if they have any drawing canvases or their display logic is referenced by pixels (which is pretty common in WinForms custom painting.)

For this reason, setting your forms to use DPI scaling might solve your issue

Also check out some of these posts in SO that might help explain your observations:
How to write WinForms code that auto-scales to system font and dpi settings?
How to control the font DPI in .NET WinForms app
How to configure an app to run correctly on a machine with a high DPI setting (e.g. 150%)?

Chris Schaller
  • 13,704
  • 3
  • 43
  • 81