Skip to content

Allow set font application-wide #3001

@RussKie

Description

@RussKie

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. #1122, #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

Metadata

Metadata

Assignees

Labels

api-approved(4) API was approved in API review, it can be implementedapi-suggestion(1) Early API idea and discussion, it is NOT ready for implementation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions