Detect Windows Font Size (100%, 125%, and 150%)

Detect Windows font size (100%, 125%, and 150%)

The correct way of handling variable DPI settings is not to detect them and adjust your controls' sizes manually in a switch statement (for starters, there are far more possibilities than those you show in your sample if statement).

Instead, you should set the AutoScaleMode property of your form to AutoScaleMode.Dpi and let the framework take care of this for you.

Add the following code to your form's constructor (or set this property at design time):

this.AutoScaleMode = AutoScaleMode.Dpi;

Although you might prefer to use AutoScaleMode.Font. For more information on automatic scaling, see the MSDN documentation.

How to detect the windows font size(100%, 125%, 150%) in java

I did it in the following way:

Display.getCurrent().getDPI().x

Here, based on the return value(96, 120 or 144) it can be determined if the size is 100%, 125% or 150% respectively

Need to find you if the user is using magnified font size 125% or 150% in win 7

You can read Graphics.DpiX to discern this.

Multiply Graphics.DpiX by 100 and divide by 96 and you will have the percentage font scaling. This is true because 100% font scaling equates to 96dpi.

Be warned that if your application is not marked as DPI aware then when the user sets font scaling to 150% the DpiX property will report 96. Off the top of my head I do not know whether or not standard WinForms apps are marked as DPI aware.

150 percent font made text be cut

I guess you are changing the screen DPI, so change the form's AutoScaleMode property to AutoScaleMode.Dpi.

If you are just changing the font size, set it to AutoScaleMode.Font.

More information about this:

Automatic Scaling in Windows Forms

Windows scale is affecting my application font

I used SetProcessDPIAware and it fixed the issue and now the application works on different scale modes and there is only an issue with combobox size that change. I found already a ticket opened on git here for the combobox.

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
SetProcessDPIAware();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}

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


Related Topics



Leave a reply



Submit