开发者

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

开发者 https://www.devze.com 2023-03-02 22:07 出处:网络
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?

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 开发者_StackOverflow社区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.


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


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.


// 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

精彩评论

暂无评论...
验证码 换一张
取 消