GoldenUser
GoldenUser

Reputation: 365

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

For a windows application (C#), is it possible to adjust the entire application (including all forms) to use system font settings for size rather than using fixed sizes?

This is for users with visual impairment who have set a bigger font size on their machines. Is it possible for the application to adjust the font according to what the user has.

Upvotes: 4

Views: 11145

Answers (3)

AsifNoor
AsifNoor

Reputation: 1

// 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);
}

Upvotes: 0

Jason Moore
Jason Moore

Reputation: 3374

In the constructors of your forms (before calling InitializeComponent()), I would try setting the Font property of your forms equal to System.Drawing.SystemFonts.DefaultFont. If your controls (ex: textboxes) don't specify a specific font then I believe they inherit their font properties from their parent containers (i.e. forms).

There are other more specific system fonts (like the default setting for the Caption's font) in the System.Drawing.SystemFonts class. You may want to investigate those further as well.

Upvotes: 2

Ivan Ferić
Ivan Ferić

Reputation: 4763

You should set the AutoScaleMode property of all your forms to the value AutoScaleMode.Font if you want your application to be scaled by system font, or AutoScaleMode.Dpi if you want it to be scaled by windows DPI settings.

Here you can find some more info - http://msdn.microsoft.com/en-us/library/ms229605.aspx

Upvotes: 3

Related Questions