Skip to content

[NET11 new API] Visual Styles feature (postponed from .NET 9 and .NET 10) #14587

Closed

Description

@KlausLoeffelmann

Rationale

WinForms needs a versioned Visual Styles path that allows accessibility-driven rendering improvements to ship without breaking existing pixel-perfect applications. The feature should be opt-in, predictable, and specific to WinForms visual rendering rather than becoming a general theming system.

Classic CheckBox controls give users a very small practical landing area and use a design language that many customers no longer accept as modern. That matters for accessibility: small glyph-focused targets are harder for touch, pen, low-vision users, and users with motor impairments. Modern checkbox rendering should increase the practical hit target, make the state easier to recognize, and keep compatibility through explicit visual-style versioning.

RadioButton controls, also known as option buttons, have the same landing-area and visual-language problem. Since WinForms has already introduced new renderers for Button, extending the overhaul to the whole button family is a lower-risk and more coherent path than modernizing each control independently. The normal Button should also receive a .NET 11 visual style based on current Fluent Design styling, including rounded corners.

TextBoxBase is missing an effective Padding API. This is also an accessibility issue in dense forms. In particular, dark surfaces make the problem more visible: a white TextBox border on a dark background creates a much stronger contrast boundary than the complementary classic/light appearance. In forms with many Label/TextBox pairs, users can lose track of grouping and reading flow. Versioned Visual Styles give WinForms a compatibility-safe way to modernize TextBox rendering, expose padding, and improve spacing without forcing layout changes on existing applications.

What this feature is and is not

  • We have NO intention to introduce full-blown theming support in WinForms with this.
  • We want to be very mindful with this topic, since there are a lot of theming standards already out there.
  • The API is meant as an opt in: You can use it, but if you do not, nothing should break. Existing theming concepts should continue to work as they are.

Versioning Visual Styles for current and future A11Y requirements

Visual Styles Mode versions how controls render in different .NET releases. This is essential for backward compatibility when accessibility requirements or platform design expectations require larger minimum sizes, different padding, different margins, updated hit testing, or updated border rendering.

In .NET 11, the first versioned Visual Styles target is Net11. Applications that do not opt in keep existing rendering. Applications that do opt in can use the .NET 11 rendering contract directly, use Latest to follow the latest stable Visual Styles contract, or use LatestPreview when they intentionally want preview/out-of-band Visual Styles behavior before it is promoted into a stable version.

The APIs are added to Application and Control, with VisualStyles in their names, so both new and existing applications can opt into enhanced rendering while maintaining compatibility with previous framework versions.

API Proposal

namespace System.Windows.Forms;

public enum VisualStylesMode : short
{
    Inherit = -1,
    Classic = 0,
    Disabled = 1,
    Net11 = 2,
    Latest = short.MaxValue,
}
namespace System.Windows.Forms;

public static partial class Application
{
    public static VisualStylesMode VisualStylesModeDefault { get; }
    public static void SetVisualStylesModeDefault(VisualStylesMode visualStylesMode);
}
namespace System.Windows.Forms;

public partial class Control
{
    public VisualStylesMode VisualStylesMode { get; set; }

    public event EventHandler? VisualStylesModeChanged;

    protected virtual void OnVisualStylesModeChanged(EventArgs e);

    // Allows a derived control to set a particular Visual Styles mode for compatibility reasons.
    protected virtual VisualStylesMode DefaultVisualStylesMode { get; }
}
namespace System.Windows.Forms;

public abstract class TextBoxBase : Control
{
    public new Padding Padding { get; set; }
}
namespace System.Windows.Forms;

public enum Appearance
{
    Normal = 0,
    Button = 1,
    ToggleSwitch = 2,
}
Namespace Microsoft.VisualBasic.ApplicationServices

    Public Class ApplyApplicationDefaultsEventArgs
        Inherits EventArgs

        Public Property VisualStylesMode As VisualStylesMode
    End Class
End Namespace

The VB Application Framework wiring completes work anticipated back in the .NET 9 Visual Styles attempt: WindowsFormsApplicationBase.OnInitialize already carries a comment stating that HighDpiMode, ColorMode, and VisualStylesMode are fed to ApplyApplicationDefaultsEventArgs, but only HighDpiMode/ColorMode were ever actually wired up. This closes that gap, following the exact same shadow-instance-field pattern already used for ColorMode/HighDpiMode (WindowsFormsApplicationBase keeps its own _visualStylesMode field, seeded independently of Application.DefaultVisualStylesMode, and applies it via Application.SetDefaultVisualStylesMode once at the end of OnInitialize - the only call site that ever touches the static setter in the supported flow, so SetDefaultVisualStylesMode's write-once semantics are not at risk of a spurious double-set).

API Usage

Application.SetDefaultVisualStylesMode(VisualStylesMode.Net11);
Application.Run(new MainForm());
Application.SetDefaultVisualStylesMode(VisualStylesMode.LatestPreview);
Application.Run(new VisualStylesPreviewForm());
checkBox1.VisualStylesMode = VisualStylesMode.Net11;
checkBox1.Appearance = Appearance.ToggleSwitch;

textBox1.VisualStylesMode = VisualStylesMode.Net11;
textBox1.Padding = new Padding(8, 4, 8, 4);

Risks - limited, only when opted in

  • Updated control metrics WILL affect pixel-perfect layouts.
  • Rendering, hit testing, focus cues, UIA bounds, and keyboard behavior must stay aligned for the button family.
  • TextBoxBase.Padding WILL change layout expectations for derived controls and must be constrained to Visual Styles modes where the new rendering contract applies.
  • Owner-drawn controls, custom renderers, and inherited controls must have clear compatibility behavior.

Will this feature affect UI controls?

Yes. This feature intentionally affects rendering, spacing, and practical hit targets for selected controls when the application or control opts into a Visual Styles mode beyond classic behavior. The initial focus is the button family and TextBoxBase-derived controls:

  • CheckBox
  • RadioButton
  • Button
  • TextBox
  • RichTextBox
  • NumericUpDown

Designer support is expected for localized property categories/descriptions and CodeDOM serialization-safe defaults. Existing applications that do not opt in should preserve their current rendering and layout behavior.

Status Checklist

Work tracker

Activity

  1. added
    api-suggestion
    on May 30, 2026
  2. changed the title [-][.NET 11 API Proposal] Visual Styles feature[/-] [+]Visual Styles feature (postponed from .NET 9 and .NET 10)[/+] on May 30, 2026
  3. added
    a11y-MAS
    and removed
    api-suggestion
    on May 30, 2026
  4. changed the title [-]Visual Styles feature (postponed from .NET 9 and .NET 10)[/-] [+][NET11 new API] Visual Styles feature (postponed from .NET 9 and .NET 10)[/+] on May 30, 2026
  5. added this to the .NET 11 milestone on May 30, 2026
  6. added
    At risk 10-30
    on May 30, 2026
  7. removed
    a11y-MAS
    At risk 10-30
    on Jul 14, 2026
  8. added
    NewApi-Net11
    on Jul 18, 2026
  9. KlausLoeffelmann commented on Jul 18, 2026

    @KlausLoeffelmann
    MemberAuthor

    Amendment (post-implementation): change-impact model and EffectiveVisualStylesMode visibility

    This extends the originally approved surface. Implementation showed that base
    OnVisualStylesModeChanged performed no preferred-size cache invalidation and no layout
    transaction, unlike OnFontChanged. Every metric-changing control therefore had to
    reimplement a four-step, ordering-critical protocol.

    The concrete motivating bug was TextBoxBase running parent layout before
    UpdateStyles(), so containers measured pre-transition metrics and live mode switches
    could clip until control recreation. A top-level switch also triggered one full parent
    layout per affected control—O(controls × containers)—against partially transitioned
    state.

    Addition A — EffectiveVisualStylesMode

    EffectiveVisualStylesMode changes from private protected to protected and remains
    non-virtual. Custom controls must render against the effective value because the raw
    VisualStylesMode does not include the High Contrast or Disabled clamp.

    Non-virtual is deliberate: this property is the accessibility policy enforcement point.
    The customization hook remains virtual DefaultVisualStylesMode, upstream of the clamp.

    Addition B — impact declaration

    protected enum VisualStylesModeChangeImpact { None, Repaint, NonClientUpdate, Metrics }
    
    protected virtual VisualStylesModeChangeImpact GetVisualStylesModeChangeImpact(
        VisualStylesMode oldMode,
        VisualStylesMode newMode);

    Derived controls declare what changes; the base class owns how and in what order to
    react. The default Repaint makes custom controls correct without imposing layout cost.
    Metric changes now produce one coalesced layout pass per container after the complete
    subtree has transitioned, so the ordering bug is structurally impossible.

    Behavioral note

    Base OnVisualStylesModeChanged is now the dispatcher. It early-outs when the effective
    mode is unchanged, clears caches and updates styles/non-client state according to the
    declared impact, and coalesces child transitions and layout. Existing overrides that call
    base inherit this behavior. The change is recorded in
    docs/Net11Api_05_VisualStylesMode.HighRiskReview.md.

    Expected Questions

    Q: Why isn't EffectiveVisualStylesMode virtual?
    A: It is the accessibility enforcement point (High Contrast ⇒ Classic, Disabled honored). A
    virtual authoritative property is a contradiction — derived controls could silently break the HC
    guarantee for exactly the users it protects. The supported customization point is the virtual
    DefaultVisualStylesMode, upstream of the clamp.

    Q: Why an enum + virtual method instead of an ExtendedStates bit (the UserPreferredSizeCache
    pattern)?

    A: Impact has four levels, not two, and is pair-dependent: Classic→Net11 may be Metrics while
    Net11→Latest is Repaint for the same control. A static bit cannot express either.

    Q: Why is the default Repaint rather than the conservative Metrics?
    A: Repaint is the safe and cheap default: a control that doesn't override gets correct rendering
    with no layout cost. Defaulting to Metrics would tax every existing custom control with full
    layout passes on every switch to protect a case (metrics changing without the author knowing) that
    implies deeper bugs anyway.

    Q: Is the new base-class behavior a breaking change for existing OnVisualStylesModeChanged
    overriders?

    A: The API is new in this release; no stable-release overriders exist. Within the release, the change
    is documented in the high-risk review notes, and the amendment removes work from overriders rather
    than adding requirements.

    Q: Why does Application.SetDefaultVisualStylesMode not follow SetCompatibleTextRenderingDefault
    ("Default" last)?

    A: Modern precedent is SetHighDpiMode (3.0), SetDefaultFont (6), SetColorMode (9);
    SetDefaultFont places Default first. Decisively, the method pairs with the actual property
    Application.DefaultVisualStylesMode and mirrors its name. SetCompatibleTextRenderingDefault
    (NetFx 2.0) has no corresponding Application property; its grammar does not transfer. Considered
    and rejected.

  10. KlausLoeffelmann commented on Jul 29, 2026

    @KlausLoeffelmann
    MemberAuthor

    Merged into main and Preview7.

  11. locked and limited conversation to collaborators on Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

NewApi-Net11area-Themingarea-a11y-generalarea-modernization-impediment

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions