question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow set font application-wide

See original GitHub issue

Is your feature request related to a problem? Please describe.

The default font has been updated in .NET Core 3.0 (#656) and documented. However for some users there is still an element of surprise when they migrate their apps to .NET Core. We’ve received several questions regarding different sizes of forms (e.g. https://github.com/dotnet/winforms/issues/1122, https://github.com/dotnet/winforms/issues/1827, etc.).

Whilst the new default font is here to stay, some users may wish to retain the original font (e.g. due to a design of their app). However for an application with more than a handful of forms, setting the original font may be tedious and cumbersome exercise.

Describe the solution you’d like

Add the ability to set an application-wide font, similar to SetHighDpiMode() or SetCompatibleTextRenderingDefault() methods.

  • This method must be “run only once” kind, i.e. a user may not be allowed to invoke it once an app has started.
  • Any form that doesn’t explicitly specify its own font, must inherit the application default font.

API Proposal

namespace System.Windows.Forms
{
    public partial class Application
    {
        public void SetDefaultFont(Font font);
    }
}

API Usage

class Program
{
    [STAThread]
    static void Main()
    {
        Application.SetHighDpiMode(HighDpiMode.SystemAware);
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        Application.SetDefaultFont(new Font(new FontFamily("Microsoft Sans Serif"), 8f));

        Application.Run(new Form1());
    }
}

Will this feature affect UI controls?

No

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:26 (24 by maintainers)

github_iconTop GitHub Comments

3reactions
RussKiecommented, May 14, 2021

We can now implement this proposal. https://github.com/dotnet/winforms/issues/4909 will facilitate a communication of the the font information to the designer process.

2reactions
RussKiecommented, May 16, 2021

And I see that size of the form is the same on all of your screenshots, it means that font scaling not working

They are in fact different in net6.0 scenarios 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change the default font in Word
To use your favorite font in Word all the time, set it as the default. Go to Home, and then select the Font...
Read more >
How to set the default font for a WPF application?
I want to be able to define a font family for my WPF application. Preferably using a resource dictionary as a theme referenced...
Read more >
How to Perfectly Set Up Typography & Fonts in Elementor
Loading fonts from Google also causes an issue with GDPR compliance! Userdata are sent to Google before the user has the ability to...
Read more >
Change the Default Font for All Your Word Docs - YouTube
Learn how to easily change the default font in Microsoft Word so that it matches your preferences and any style guides that you...
Read more >
Set global font size for report to 13pt [duplicate]
Koma-script allows you to set the main font to an arbitrary size, and scales the other dimensions appropriately. You can change
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found