Skip to content

[NET 11 API Proposal] Application APIs for Windows accent color and Accessibility text scaling #14583

Description

@KlausLoeffelmann

Background and motivation

This proposal adds two foundational Application APIs for modern WinForms UI:

  • Application.GetWindowsAccentColor() provides the user's Windows accent color for modern Visual
    Styles renderers and other application chrome.
  • Application.SystemTextSize exposes the Windows Accessibility Text size factor, while
    SystemTextSizeChanged notifies applications when fonts and font-dependent layout need to be
    recalculated.

WinForms already reads the Accessibility text-size setting when it creates the default font, but
the factor is not public and changes made while the application is running are not reported.
Applications and future control APIs therefore cannot reliably remeasure text or update cached
font-dependent dimensions.

SystemTextSize represents Settings > Accessibility > Text size, not display DPI scaling.
DPI remains covered by HighDpiMode, WM_DPICHANGED, and the existing DPI events.

API proposal

namespace System.Windows.Forms;

public sealed partial class Application
{
    /// <summary>
    ///  Gets the user's current Windows accent color.
    /// </summary>
    /// <returns>
    ///  The accent color selected in Windows personalization settings.
    /// </returns>
    public static Color GetWindowsAccentColor();

    /// <summary>
    ///  Gets the current Windows Accessibility text-size factor
    ///  (Settings > Accessibility > Text size), as a multiplier in the
    ///  range 1.0-2.25.
    /// </summary>
    /// <remarks>
    ///  The value is read on every access and is independent of display DPI.
    ///  On Windows versions earlier than Windows 10 version 1507, this
    ///  property returns 1.0.
    /// </remarks>
    public static double SystemTextSize { get; }

    /// <summary>
    ///  Occurs when the Windows Accessibility text-size setting changes.
    /// </summary>
    /// <remarks>
    ///  This event is not raised on Windows versions earlier than Windows 10
    ///  version 1507.
    /// </remarks>
    public static event EventHandler? SystemTextSizeChanged;
}

public partial class Form
{
    /// <summary>
    ///  Occurs on this top-level Form when the Windows Accessibility
    ///  text-size setting changes.
    /// </summary>
    public event EventHandler? SystemTextSizeChanged;

    /// <summary>
    ///  Raises the SystemTextSizeChanged event.
    /// </summary>
    protected virtual void OnSystemTextSizeChanged(EventArgs e);
}

Usage

Modern renderers can use the current Windows accent color directly:

Color accentColor = Application.GetWindowsAccentColor();

An application can update its font and trigger layout when the Accessibility text-size factor
changes. The calculation must use a stable base size rather than repeatedly multiplying the
already-scaled font:

public sealed class MainForm : Form
{
    private const float BaseFontSize = 9.0f;

    protected override void OnSystemTextSizeChanged(EventArgs e)
    {
        base.OnSystemTextSizeChanged(e);

        Font = new Font(
            Font.FontFamily,
            BaseFontSize * (float)Application.SystemTextSize,
            Font.Style,
            Font.Unit);

        PerformLayout();
    }
}

Applications that replace fonts repeatedly should retain and dispose the font instances they own.
The framework deliberately does not perform automatic font scaling or relayout because font and
layout policies are application-specific.

Why the event is also available on Form

The process-wide Application.SystemTextSizeChanged event is useful for application-level caches
and services. The Form event provides the natural UI-thread and window-lifetime notification for
updating a particular visual tree. It also avoids requiring forms to subscribe to a static event,
which could keep them alive, or requiring applications to override WndProc.

Behavior

  • GetWindowsAccentColor() reads Windows.UI.ViewManagement.UISettings and returns the selected
    accent color or the operating system's default accent color.
  • SystemTextSize returns a factor rather than a percentage so it can be applied directly and
    avoids repeated percentage conversions.
  • Windows reports text-size changes through a broader Accessibility notification. WinForms
    rereads the factor and raises SystemTextSizeChanged only when the value actually changed.
  • Applications opt in simply by subscribing to an event or overriding
    Form.OnSystemTextSizeChanged; existing applications do not change behavior.
  • The Accessibility text-size APIs require Windows 10 version 1507 or later. On earlier versions,
    SystemTextSize returns 1.0 and change events are not raised.

Will this feature affect UI controls?

The APIs do not automatically change existing controls. They provide the shared color and
text-scaling information needed by modern renderers, applications, and follow-up control APIs to
update their own rendering, measurement, and layout.

Designer impact: Form.SystemTextSizeChanged appears as a standard event. There are no new
serialization requirements.

Accessibility impact: Applications can react when the user changes the Windows Accessibility
Text size setting while the application is running.

Localization: No user-visible strings are introduced.

Metadata

Metadata

Labels

NewApi-Net11Tracks issues for public APIs targeted for .NET 11.api-suggestion(1) Early API idea and discussion, it is NOT ready for implementationblockingUsed by the API Review Boardneeds-area-labeltenet-accessibilityMAS violation, UIA issue; problems with accessibility standards

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions