Question

I am developing a Windows Forms application in C# for use in an office. Thus far, with Anchoring and Autosizing, the controls lay themselves out well at the default form size, when maximized, etc.

The form does not look good in a conference room, on a large projected screen. Text is too small to be read easily.

We run Windows 7 on our machines, so as an experiment I raised the Display rendering from 100% to 150%. This made the text on the controls blurry, so I did some research and then added this to my Main() method.

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetProcessDPIAware;

This worked really well - the app scaled up, the controls were large and readable, and everything continued to lay out well. The only problem is that changing the Display rendering forces you to log out, it inconvenient, and realistically our users will never do it. The computers are likely to stay at 100%.

Can I do this from within the application? I've seen a lot of questions about forcing an app down to 96 DPI, but is it possible to force it UP to 120 or 144 DPI?

Or maybe there is a different and better means to achieve the same goal? I would like to avoid building a separate "Presentation Mode" interface with large fonts if at all possible.

Was it helpful?

Solution

Because of the effort that would go into properly working with DPI in Windows Forms, we ended up pursuing a much easier route: changing the fonts of the form.

If all of the controls are set to AutoScale by Font (which is their default), you can override the system font on a per-form basis.

this.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

Some controls don't pull from the form's font, and would have to be set individually, such as menustrips.

menuStrip1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

We changed font size for the form to 14 and for the menus to 15 to increase readability, and changed them back to their original values to return to standard mode.

Note that just as some controls will ignore the form font by default, many (if not all) controls can and will ignore this if you manually configure their font (such as making text bold, or italics, etc.). Every instance of this needs to be handled individually.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top