How to use system font settings for a Windows C # application

For a Windows application (C #), is it possible to configure the entire application (including all forms) to use system font settings for size, and not for fixed sizes?

This is for visually impaired users who have installed a larger font size on their machines. Is it possible for the application to customize the font according to what the user has.

+3
source share
3 answers

In the designers of your forms (before calling InitializeComponent()), I will try to set the Font property of your forms to equal System.Drawing.SystemFonts.DefaultFont. If your controls (for example: text fields) do not indicate a specific font, I assume that they inherit their font properties from their parent containers (i.e. Forms).

In the System.Drawing.SystemFonts class, there are other more specific system fonts (such as the default setting for the Caption font). You might also want to study them.

+2
source

You must set the property for AutoScaleModeall your forms to a value AutoScaleMode.Fontif you want your application to be scaled by the system font or AutoScaleMode.Dpiif you want to scale it using the DPI window settings.

- http://msdn.microsoft.com/en-us/library/ms229605.aspx

+2
// Get dpi width
float x = this.CreateGraphics().DpiX;

// if screen is width
if (x == 120)
    // Get big image from Resources
    this.BackgroundImage = Properties.Resources.BigImage;

else if (x==96)
{
    // Get small image from Resources
    this.BackgroundImage = Properties.Resources.loading49;

    this.BackColor = ColorTranslator.FromHtml("#E6E6E6");
    this.button2.Size = new Size(85, 30);
    this.button1.Size = new Size(75, 24);
    this.textBox1.Size = new Size(150, 40);
}
0
source

All Articles