Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force a Windows Forms C# application to ignore when a user choose 125% or 150% for the OS font size?

Tags:

c#

winforms

I need a quick way of forcing my C# Windows Forms application to not scale fonts when a user choose a larger or smaller percentage in the OS settings.

Is this even possible?

like image 331
Andrew Avatar asked Nov 03 '10 16:11

Andrew


People also ask

How do I load a Windows Form?

Loader is an operating system that is used for loading Programs and Libraries. It is one of the essential stages in the process of starting a program. Click New >> Project >> Visual C# >> Windows >> Windows Forms Application. Enter your Project name and click OK.

How can I bring my application window to the front?

When the user has the program minimized and presses F3 a global hook keys gets the press and translation window should be made and brought to front.


1 Answers

Here is what worked for me...

        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;         this.Font = new System.Drawing.Font("Arial", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel, ((byte)(0))); 

The above two lines are copied from my BaseForm.Designer.cs file, but basically I found two easy steps to get "no font scaling":

  1. Set AutoScaleMode to None.

  2. Use "Pixel" as the Unit Type for all Fonts, instead of the default Point value.

As far as if you should let Windows scale your fonts or not, that's up to you. I for one don't like the design, so if I feel my application needs to be scaled, I'll do it myself, with my own options and design.

Over the years of speaking with actual end-users, I've also found that most of them have no idea about DPI settings, and if they have anything other than the default set, it wasn't because they wanted it that way... and they just never noticed because all they use is the web browser and maybe Excel and Microsoft Word (which use whatever font they set it to).

If my application had respected the system font settings, they wouldn't have liked it as much == less sales, because it would have had this huge ugly font like the system dialogs do (and they don't know how to change it, but they don't care about system dialogs they never use).

like image 69
eselk Avatar answered Sep 23 '22 09:09

eselk