Skip to content

Add versioned .NET 11 Visual Styles#14737

Open
KlausLoeffelmann wants to merge 62 commits into
dotnet:mainfrom
KlausLoeffelmann:Net11Api_05_VisualStylesMode
Open

Add versioned .NET 11 Visual Styles#14737
KlausLoeffelmann wants to merge 62 commits into
dotnet:mainfrom
KlausLoeffelmann:Net11Api_05_VisualStylesMode

Conversation

@KlausLoeffelmann

@KlausLoeffelmann KlausLoeffelmann commented Jul 14, 2026

Copy link
Copy Markdown
Member

Closes #14587.
Contributes to #14694.

Bug fixes

Depends on #14733 for the final SystemVisualSettings renderer composition.
SystemVisualSettings proposal: KlausLoeffelmann#14
Integrated validation: #14768

  • Adds versioned application- and control-level VisualStylesMode opt-in with ambient
    inheritance and Visual Basic Application Framework wiring.
  • Modernizes Button, CheckBox, RadioButton, ToggleSwitch, TextBoxBase, RichTextBox, and
    UpDown rendering while preserving classic defaults.
  • Replaces the animation pacer with an absolute-schedule high-resolution waitable timer,
    generation-safe lifecycle, allocation-free dispatch, and per-UI-thread managers.
  • Adds the protected VisualStyles change-impact model so the base Control owns style,
    non-client, cache, and coalesced layout ordering.
  • Fixes live TextBox mode switches so AutoSize TableLayoutPanel rows remeasure after the
    subtree has fully transitioned.
  • Includes focused timing, concurrency, allocation, lifecycle, rendering, layout, DPI,
    serialization, and accessibility coverage.

The branch intentionally retains only an internal accent-color bridge for standalone
compilation. Integration-3 replaces that bridge and the modern renderer consumers with
Application.SystemVisualSettings; its full x86, x64, and ARM64 CI matrix passes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces versioned Visual Styles opt-in for WinForms (targeting .NET 11), along with supporting infrastructure (accent color, animation dispatch, and control/layout updates) and corresponding unit/integration coverage to preserve classic defaults while enabling modern rendering when opted in.

Changes:

  • Add VisualStylesMode (app default + control ambient inheritance plumbing) and wire it through the VB Application Framework.
  • Modernize rendering/metrics behavior for button-family controls and UpDown controls (including toggle-switch appearance) with new animation/rendering helpers.
  • Add/extend coverage for parent-background painting, animation renderer behavior, preferred-size/layout expectations, and new API surface tracking/resources.

Reviewed changes

Copilot reviewed 125 out of 125 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Winforms.sln Adds solution items folder for related work-order documentation.
src/test/unit/System.Windows.Forms/System/Windows/Forms/ParentBackgroundRendererTests.cs New unit tests for parent background rendering behavior.
src/test/unit/System.Windows.Forms/System/Windows/Forms/FormTests.SystemTextSize.cs Tests for Form.SystemTextSizeChanged event behavior.
src/test/unit/System.Windows.Forms/System/Windows/Forms/FormTests.cs Makes SubForm partial to share with SystemTextSize tests.
src/test/unit/System.Windows.Forms/System/Windows/Forms/DomainUpDownTests.cs Adds preferred-size test for modern visual styles sizing.
src/test/unit/System.Windows.Forms/System/Windows/Forms/CheckBoxToggleSwitchTests.cs New behavioral tests for toggle-switch appearance under Net11 visual styles.
src/test/unit/System.Windows.Forms/System/Windows/Forms/ButtonTests.cs Adds tests for adapter/renderer recreation and DPI update behavior.
src/test/unit/System.Windows.Forms/System/Windows/Forms/ButtonPopupAdapterTests.cs Adds preferred-size test for popup default state.
src/test/unit/System.Windows.Forms/System/Windows/Forms/ApplicationTests.SystemTextSize.cs New tests for Application.SystemTextSize* APIs.
src/test/unit/System.Windows.Forms/System/Windows/Forms/ApplicationTests.cs Makes test class partial and adds SetDefaultVisualStylesMode write-once test.
src/test/unit/System.Windows.Forms/System/Windows/Forms/AnimatedControlRendererTests.cs New unit tests for AnimatedControlRenderer contract.
src/test/unit/System.Windows.Forms/System/Windows/Forms/AccessibleObjects/UpDownBase.UpDownButtons.UpDownButtonsAccessibleObjectTests.cs Adds UIA hit-test/invoke test for modern UpDown button layout.
src/test/unit/System.Windows.Forms/NumericUpDownTests.cs Adds preferred-size test for modern visual styles sizing.
src/test/integration/WinformsControlsTest/Buttons.cs Adds integration UI entry point for visual-styles button samples.
src/test/integration/UIIntegrationTests/NumericUpDownTests.cs Adds integration test for modern chrome layout expectations.
src/System.Windows.Forms/System/Windows/Forms/VisualStylesMode.cs Introduces VisualStylesMode enum.
src/System.Windows.Forms/System/Windows/Forms/SystemTextSizeAwareness.cs Introduces SystemTextSizeAwareness enum (NET11+ guarded).
src/System.Windows.Forms/System/Windows/Forms/Rendering/CheckBox/ModernCheckBoxStyle.cs Adds internal style enum for modern checkbox/toggle rendering.
src/System.Windows.Forms/System/Windows/Forms/Rendering/Button/PopupButtonTextEffect.cs Adds popup key-cap text relief options enum.
src/System.Windows.Forms/System/Windows/Forms/Rendering/Button/PopupButtonRenderOptions.cs Adds tunable render options for popup key-cap renderer.
src/System.Windows.Forms/System/Windows/Forms/Rendering/Button/PopupButtonRenderContext.cs Adds render context container for popup key-cap renderer.
src/System.Windows.Forms/System/Windows/Forms/Rendering/Button/PopupButtonMetric.cs Adds DPI-neutral magnitude enum used by popup key-cap renderer.
src/System.Windows.Forms/System/Windows/Forms/Rendering/Button/PopupButtonEasing.cs Adds easing functions for popup key-cap animations.
src/System.Windows.Forms/System/Windows/Forms/Rendering/Button/PopupButtonAnimationState.cs Adds immutable animation snapshot struct for popup key-cap.
src/System.Windows.Forms/System/Windows/Forms/Rendering/Animation/AnimationManager.cs Adds process-wide animation dispatcher powered by HighPrecisionTimer.
src/System.Windows.Forms/System/Windows/Forms/Rendering/Animation/AnimationManager.AnimationRendererItem.cs Adds internal renderer-item bookkeeping for AnimationManager.
src/System.Windows.Forms/System/Windows/Forms/Rendering/Animation/AnimationCycle.cs Adds animation cycle enum (once/loop/bounce).
src/System.Windows.Forms/System/Windows/Forms/Rendering/Animation/AnimatedControlRenderer.cs Adds base class for animated renderers and accent-color caching.
src/System.Windows.Forms/System/Windows/Forms/ParentBackgroundRenderer.cs Adds helper to paint parent background respecting existing clips.
src/System.Windows.Forms/System/Windows/Forms/Layout/PropertyNames.cs Adds VisualStylesMode to layout property-name constants.
src/System.Windows.Forms/System/Windows/Forms/Form.SystemTextSize.cs Adds per-form SystemTextSize change detection/event (NET11+ guarded).
src/System.Windows.Forms/System/Windows/Forms/Form.cs Recreates handle on High Contrast transition; routes WM_SETTINGCHANGE (NET11+).
src/System.Windows.Forms/System/Windows/Forms/Controls/UpDown/UpDownBase.UpDownEdit.cs Adds focus invalidation and pins edit VisualStylesMode behavior.
src/System.Windows.Forms/System/Windows/Forms/Controls/UpDown/UpDownBase.UpDownButtons.UpDownButtonsAccessibleObject.DirectionButtonAccessibleObject.cs Fixes bounds computation to honor stacked vs side-by-side layout.
src/System.Windows.Forms/System/Windows/Forms/Controls/UpDown/UpDownBase.UpDownButtons.cs Adds side-by-side layout support and modern rendering state computation.
src/System.Windows.Forms/System/Windows/Forms/Controls/UpDown/NumericUpDown.cs Adjusts preferred width computation for modern button-group sizing.
src/System.Windows.Forms/System/Windows/Forms/Controls/UpDown/DomainUpDown.cs Adjusts preferred width computation for modern button-group sizing.
src/System.Windows.Forms/System/Windows/Forms/Controls/TextBox/TextBox.cs Avoids double-counting scrollbar reservation in modern VisualStylesMode; improves layout invalidation.
src/System.Windows.Forms/System/Windows/Forms/Controls/TextBox/MaskedTextBox.cs Avoids classic nonclient border drawing in modern VisualStylesMode.
src/System.Windows.Forms/System/Windows/Forms/Controls/RichTextBox/RichTextBox.cs Adds modern nonclient reservation logic + scrollbar padding handling; provokes client-area recalculation.
src/System.Windows.Forms/System/Windows/Forms/Controls/PropertyGrid/PropertyGrid.cs Pins PropertyGrid effective VisualStylesMode to Classic to preserve internal alignment.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/RadioButton.cs Adds modern glyph/toggle rendering paths and lifecycle hooks; integrates animations.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/FlatButtonAppearance.cs Adds modern default mouse-over/down colors (Net11 visual styles) with serialization helpers.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/RadioButtonStandardAdapter.cs Routes standard adapter selection through dark/modern factory.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/RadioButtonPopupAdapter.cs Routes popup adapter selection through dark/modern factory.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/RadioButtonModernAdapter.cs Adds modern adapter using animated glyph renderer.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/RadioButtonFlatAdapter.cs Routes flat adapter selection through dark/modern factory.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/DarkMode/SystemButtonDarkModeRenderer.cs Updates system button renderer to support focus/parent background and new signatures.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/DarkMode/ModernFlatButtonRenderer.cs Adds modern flat button renderer implementation.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/DarkMode/ModernButtonColorMath.cs Adds shared palette/state color math for modern button rendering.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/DarkMode/IButtonRenderer.cs Extends renderer interface to include control context + backColor-aware text color.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/DarkMode/FlatButtonDarkModeRenderer.cs Updates flat renderer for new signatures and DPI-aware border thickness.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/DarkMode/DarkModeAdapterFactory.cs Uses owner-drawn adapters for dark mode and Net11+ visual styles.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/DarkMode/ButtonBackColorAnimator.cs Adds animated background-color transitions for interaction states.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/CheckBoxStandardAdapter.cs Routes standard adapter selection through dark/modern factory.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/CheckBoxPopupAdapter.cs Routes popup adapter selection through dark/modern factory.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/CheckBoxModernAdapter.cs Adds modern checkbox adapter using animated glyph renderer.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/CheckBoxFlatAdapter.cs Routes flat adapter selection through dark/modern factory.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/ButtonPopupAdapter.cs Adds preferred-size override consistent with popup layout.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/ButtonBaseAdapter.LayoutOptions.cs Adds layout option flags and restores previous word-wrap state correctly.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonInternal/ButtonBaseAdapter.cs Adds modern preferred-size helpers and improves image clipping behavior.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/ButtonBase.cs Adds animation renderers, popup key-cap rendering path, and hooks for style/system color changes.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/Button.cs Removes custom OwnerDraw override; normalizes mouse enter/leave overrides.
src/System.Windows.Forms/System/Windows/Forms/Controls/Buttons/Appearance.cs Adds Appearance.ToggleSwitch and documentation.
src/System.Windows.Forms/System/Windows/Forms/Application.WindowsAccentColor.cs Adds WinRT-based accent color retrieval API.
src/System.Windows.Forms/System/Windows/Forms/Application.SystemTextSize.cs Adds SystemTextSize APIs and process-wide change notifications (NET11+ guarded).
src/System.Windows.Forms/System/Windows/Forms/Application.cs Adds DefaultVisualStylesMode and SetDefaultVisualStylesMode plumbing.
src/System.Windows.Forms/Resources/xlf/SR.zh-Hant.xlf Adds localized resources for new VisualStyles/SystemTextSize strings.
src/System.Windows.Forms/Resources/xlf/SR.zh-Hans.xlf Adds localized resources for new VisualStyles/SystemTextSize strings.
src/System.Windows.Forms/Resources/xlf/SR.tr.xlf Adds localized resources for new VisualStyles/SystemTextSize strings.
src/System.Windows.Forms/Resources/xlf/SR.ru.xlf Adds localized resources for new VisualStyles/SystemTextSize strings.
src/System.Windows.Forms/Resources/xlf/SR.pt-BR.xlf Adds localized resources for new VisualStyles/SystemTextSize strings.
src/System.Windows.Forms/Resources/xlf/SR.pl.xlf Adds localized resources for new VisualStyles/SystemTextSize strings.
src/System.Windows.Forms/Resources/xlf/SR.ko.xlf Adds localized resources for new VisualStyles/SystemTextSize strings.
src/System.Windows.Forms/Resources/xlf/SR.ja.xlf Adds localized resources for new VisualStyles/SystemTextSize strings.
src/System.Windows.Forms/Resources/xlf/SR.it.xlf Adds localized resources for new VisualStyles/SystemTextSize strings.
src/System.Windows.Forms/Resources/xlf/SR.fr.xlf Adds localized resources for new VisualStyles/SystemTextSize strings.
src/System.Windows.Forms/Resources/xlf/SR.es.xlf Adds localized resources for new VisualStyles/SystemTextSize strings.
src/System.Windows.Forms/Resources/xlf/SR.de.xlf Adds localized resources for new VisualStyles/SystemTextSize strings.
src/System.Windows.Forms/Resources/xlf/SR.cs.xlf Adds localized resources for new VisualStyles/SystemTextSize strings.
src/System.Windows.Forms/Resources/SR.resx Adds new resource strings for VisualStyles + SystemTextSize events/errors.
src/System.Windows.Forms/PublicAPI.Unshipped.txt Tracks newly introduced public/protected API surface.
src/System.Windows.Forms/GlobalSuppressions.cs Adds doc-analyzer suppression related to TextBoxBase.Padding.
src/System.Windows.Forms.Primitives/tests/UnitTests/System/Windows/Forms/Animation/HighPrecisionTimerTests.cs Adds tests for process-wide high-precision timer behavior.
src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Internals/ScaleHelper.cs Adds system text-scale factor reading helpers (registry-backed).
src/System.Windows.Forms.Primitives/src/System/Windows/Forms/Animation/HighPrecisionTimerTick.cs Adds tick payload for timer callbacks.
src/System.Private.Windows.Core/src/Windows/Win32/UI/ViewManagement/UIColorType.cs Adds WinRT ABI enum for UISettings color retrieval.
src/System.Private.Windows.Core/src/Windows/Win32/UI/ViewManagement/UIColor.cs Adds WinRT ABI struct for Windows.UI.Color.
src/System.Private.Windows.Core/src/Windows/Win32/UI/ViewManagement/IUISettings3.cs Adds WinRT ABI interface for UISettings3 color retrieval.
src/System.Private.Windows.Core/src/NativeMethods.txt Adds WinRT/Win32 interop entries needed by accent-color support.
src/System.Private.Windows.Core/src/Microsoft.Private.Windows.Core.csproj Excludes WinRT ABI sources from older/other builds as needed.
src/Microsoft.VisualBasic.Forms/tests/UnitTests/System/Windows/Forms/WindowsFormsApplicationBaseTests.vb Adds VB app-model test for VisualStylesMode flow to Application.
src/Microsoft.VisualBasic.Forms/src/PublicAPI.Unshipped.txt Tracks newly introduced VB-facing API surface.
src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/ApplicationServices/WindowsFormsApplicationBase.vb Wires VisualStylesMode into ApplyApplicationDefaults and sets app default.
src/Microsoft.VisualBasic.Forms/src/Microsoft/VisualBasic/ApplicationServices/ApplyApplicationDefaultsEventArgs.vb Adds VisualStylesMode property to defaults event args.
docs/Net11Api_05_VisualStylesMode.HighRiskReview.md Documents high-risk animation infrastructure concerns for follow-up.
.github/skills/new-control-api/SKILL.md Updates contribution guidance for API tracking/version guards/experimental policy.
.github/skills/control-api-tests/SKILL.md Adds guidance for async tests and nullable contexts under CI analyzers.
.github/skills/building-code/SKILL.md Reinforces using build.cmd for CI-parity builds and analyzer enforcement.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +25 to +40
public static unsafe Color GetWindowsAccentColor()
{
HSTRING className = default;

fixed (char* pClassName = "Windows.UI.ViewManagement.UISettings")
{
PInvokeCore.WindowsCreateString((PCWSTR)pClassName, 36u, &className).ThrowOnFailure();
}

try
{
using ComScope<IInspectable> inspectable = new(null);
PInvokeCore.RoActivateInstance(className, inspectable).ThrowOnFailure();

using ComScope<IUISettings3> settings = inspectable.TryQuery<IUISettings3>(out HRESULT hr);
hr.ThrowOnFailure();
Comment on lines +16 to +55
public enum VisualStylesMode : short
{
/// <summary>
/// The control inherits its <see cref="Control.VisualStylesMode"/> from its parent, or, for a
/// top-level control, from <see cref="Application.DefaultVisualStylesMode"/>. This is the ambient
/// default and is never returned by <see cref="Control.VisualStylesMode"/> after resolution.
/// </summary>
/// <remarks>
/// <para>
/// This value is the ambient sentinel: assigning it to <see cref="Control.VisualStylesMode"/>
/// clears any local override so the value is inherited again. It is not valid as the application
/// default and is rejected by <see cref="Application.SetDefaultVisualStylesMode(VisualStylesMode)"/>.
/// </para>
/// </remarks>
Inherit = -1,

/// <summary>
/// The classic version of the visual renderer (.NET 8 and earlier), based on version 6 of the
/// common controls library.
/// </summary>
Classic = 0,

/// <summary>
/// Visual renderers are not in use - see <see cref="Application.UseVisualStyles"/>.
/// Controls are based on version 5 of the common controls library.
/// </summary>
Disabled = 1,

/// <summary>
/// The .NET 11 version of the visual renderer. Controls are rendered using the latest version
/// of the common controls library, and the adorner rendering or the layout of specific controls
/// has been improved based on the latest accessibility requirements.
/// </summary>
Net11 = 2,

/// <summary>
/// The latest stable version of the visual renderer available in the running framework.
/// </summary>
Latest = short.MaxValue
}
Comment on lines +27 to +41
private static AnimationManager? s_instance;

private static AnimationManager Instance
=> s_instance ??= new AnimationManager();

private AnimationManager()
{
_stopwatch = Stopwatch.StartNew();

// HighPrecisionTimer captures the current SynchronizationContext and posts each tick back to it,
// so OnFrameTickAsync runs on the UI thread. A SynchronizationContext is expected here because the
// first animation is always started from the UI thread.
_timerRegistration = HighPrecisionTimer.Register(OnFrameTickAsync);

Application.ApplicationExit += (sender, e) => DisposeRenderer();
Comment on lines +32 to +56
private AnimationManager()
{
_stopwatch = Stopwatch.StartNew();

// HighPrecisionTimer captures the current SynchronizationContext and posts each tick back to it,
// so OnFrameTickAsync runs on the UI thread. A SynchronizationContext is expected here because the
// first animation is always started from the UI thread.
_timerRegistration = HighPrecisionTimer.Register(OnFrameTickAsync);

Application.ApplicationExit += (sender, e) => DisposeRenderer();
}

/// <summary>
/// Disposes the animation renderers and releases the timer registration.
/// </summary>
private void DisposeRenderer()
{
// Stop the timer.
_timerRegistration.Dispose();

foreach (AnimatedControlRenderer renderer in _renderer.Keys)
{
renderer.Dispose();
}
}
KlausLoeffelmann and others added 22 commits July 18, 2026 01:26
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 27022e2a-9eb8-4f58-9bfa-e79ca0d6c559
…ng, and test cancellation/nullable guidance

- building-code: add a top-level TENET to build the solution only with build.cmd (CI parity for
  PublicAPI/analyzer enforcement and -warnAsError); a plain dotnet build is inner-loop only.
- new-control-api: new public/protected overrides must be tracked in PublicAPI.Unshipped.txt with the
  override prefix; note CS0114 (new keyword) and CS1574 (no cref to cross-assembly internal types).
- control-api-tests: async tests must pass CancellationToken (TestContext.Current.CancellationToken,
  CA2016/xUnit1051) and respect the #nullable context (CS8632).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…n Button and CheckBox toggle renderers

Introduces the (non-experimental) Visual Styles versioning API and the first modern renderers gated behind it:
- VisualStylesMode enum (Classic/Disabled/Net11/Latest); ambient Control.VisualStylesMode (+event/On-methods);
  Application.DefaultVisualStylesMode/SetDefaultVisualStylesMode; Appearance.ToggleSwitch; VB framework APIs.
- HighPrecisionTimer (internal, Primitives) as the animation frame trigger, with tests.
- AnimationManager/AnimatedControlRenderer driven by HighPrecisionTimer.
- Conservative dark-mode Standard button (owner-drawn, reachable) + modern WinUI-style Button renderer.
- CheckBox Appearance.ToggleSwitch modern toggle switch (animated, flicker-free).
- WinformsControlsTest VisualStylesButtons exploratory harness; unit tests.

Verified CI-clean with build.cmd: System.Windows.Forms, Microsoft.VisualBasic.Forms and Primitives build
with no analyzer/PublicAPI/style errors (the only remaining failure is the pre-existing BuildAssist/AxHosts
step, which is an environment limitation unrelated to these changes).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Add solution folders "Application" and "net11-VisualStylesMode" to Winforms.sln and include a detailed Markdown work order for porting non-client painting and VisualStylesMode chrome to VisualStylesNet11.

* Update solution structure to organize these items for engineering reference.
…lesNet11

Bring the non-client (NC) painting feature for TextBoxBase/TextBox from the
pinned SHA cf32e9c onto the modern VisualStylesNet11 layout, with the DECIDED
design changes and the Prompt-2 MUST-FIX items applied.

TextBoxBase.cs:
* Add VisualStyles border-padding consts + BorderThickness and the
  _triggerNewClientSizeRequest latch (reset in CreateHandle).
* Split PreferredHeight into a VisualStylesMode switch over PreferredHeightCore
  (modern) and PreferredHeightClassic (Everett-compatible). Dropped the original
  [Experimental]/WFO5000 gating - VisualStyles is not experimental on this branch.
* Add GetVisualStylesPadding / virtual GetScrollBarPadding (DPI-scaled).
* Add the VisualStylesMode >= Net11 branch to GetPreferredSizeCore.
* Add WmNcPaint / OnNcPaint / InitializeClientArea / WmNcCalcSize and the
  WM_NCCALCSIZE / WM_NCPAINT WndProc cases; wire InitializeClientArea into
  InitializeDCForWmCtlColor.
* Add NC-frame invalidation to OnGotFocus / OnLostFocus / OnSizeChanged
  (OnLostFocus now correctly guarded by VisualStylesMode, fixing the original
  asymmetry).

DECIDED design (work-order steps 6-8):
* Use the shared BufferedGraphics buffer (BufferedGraphicsManager.Current) instead
  of the per-instance NonClientBitmapCache; buffer.Render() blits to the window DC.
* Use the shipped Graphics.FillRoundedRectangle / DrawRoundedRectangle methods.
* Never-invert clamp in WmNcCalcSize (no MinimumSize); paint-time chrome
  degradation in OnNcPaint below the viable rounded-chrome height.
* Fixed the WmNcPaint double-dispose.

MUST-FIX:
* DPI-scale the corner radius and border thickness (and the degradation threshold)
  via LogicalToDeviceUnits.

TextBox.cs:
* Guard the classic PRF_NONCLIENT Fixed3D border draw so it does not double-draw
  over the modern chrome when VisualStylesMode >= Net11.

NativeMethods.txt:
* Generate GetWindowDC and NCCALCSIZE_PARAMS.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Previously InvokeCallbackAsync used 'catch (Exception ex) when (ex is not
OperationCanceledException)', which let an OperationCanceledException escape the
handler entirely. Because the callback runs as a discarded fire-and-forget task
(SyncContext.Post of '_ = InvokeCallbackAsync(...)'), the escaping OCE faulted
that task into an unobserved task exception that only surfaced via
TaskScheduler.UnobservedTaskException on GC.

Catch the OCE explicitly and ignore it when our cancellation token is signalled
(mirroring the TimerLoopAsync convention), so cancellation during timer shutdown
is a clean no-op. Genuine, non-cancellation exceptions still route to Debug.Fail.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
VisualStylesMode and DataContext are ambient via property-store absence, which is
sufficient at runtime and for the normal serialization path. But a 'truly ambient'
property the designer can reset also needs a writable 'inherit' token: the CodeDOM
serializer (PropertyMemberCodeDomSerializer) substitutes an [AmbientValue] when it is
forced to emit an otherwise-ambient property (inherited/'difference' forms, member
relationships, absolute serialization). Without it the resolved concrete value is baked
in, breaking re-inheritance in those designer scenarios.

VisualStylesMode had no inherit sentinel, so [AmbientValue] had no correct value to use.
Add one, mirroring RightToLeft.Inherit:

* Add VisualStylesMode.Inherit (= -1). It is an assignable sentinel; the resolved value
  is never Inherit (the getter resolves a stored/assigned Inherit to the parent or
  Application.DefaultVisualStylesMode), so the '>= Net11' gating elsewhere is unaffected.
* Annotate Control.VisualStylesMode with [AmbientValue(VisualStylesMode.Inherit)] and make
  the setter treat Inherit (and 'equals parent') as 'clear the local override' so it
  re-inherits; raise the change event only when the resolved value changes.
* Reject VisualStylesMode.Inherit in Application.SetDefaultVisualStylesMode (the app root
  has no parent to inherit from); also validate undefined values there.
* DataContext deliberately keeps NO [AmbientValue]: its setter stores an explicit null
  rather than clearing the override, so null would be a leaky 'inherit' sentinel. Added a
  maintainer comment explaining why.

Update PublicAPI.Unshipped.txt, SR + xlf, and the VisualStylesMode unit tests (the old
'-1 is invalid' case is now Inherit; add re-inherit, never-returns-Inherit, and
SetDefaultVisualStylesMode(Inherit) throws coverage).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…or TextBoxBase

WM_NCPAINT now passes base.WndProc a client-excluding update region (screen coordinates) so the default themed non-client paint no longer erases the edit client area (e.g. on hover) for scrollbar-bearing TextBox/RichTextBox.

Also: fix Release-only CS8175 by capturing the cached Pen (not the ref-struct scope) in the OnNcPaint focus-line local functions; extract the RichEdit-specific ScrollToCaret logic into a RichTextBox override of a new private protected virtual ScrollToCaretCore; and documentation/comment cleanups (GetVisualStylesPadding, GetPreferredSizeCore, WindowText, PaddingChanged) plus Everett capitalization.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Shrink the gap between the rounded button body and the outer focus ring and grow the body to reclaim that space. When the focus ring is not drawn, the body now expands to fill the ring+gap band via a focus-aware GetContentPadding hook, so unfocused buttons feel less cramped without changing the control's Padding.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Port the prototype material key-cap renderer into System.Windows.Forms.Rendering.Button (renamed to Popup/FlatStyle conventions, no MaterialKey naming). Button owner-paints FlatStyle.Popup under modern visual styles or dark mode via a timer-driven AnimatedPopupButtonRenderer that interpolates hover/press channels through the shared AnimationManager, mirroring the CheckBox toggle switch. Border width/color are read from FlatButtonAppearance. The old PopupButtonDarkModeRenderer is removed; the dark-mode adapter keeps the modern renderer for Popup layout only.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…Button

Route the Appearance.Button rendering of CheckBox and RadioButton through DarkModeAdapterFactory so it reuses the modern ButtonDarkModeAdapter/renderers under dark mode or modern visual styles, matching modern push buttons (including checked-as-pressed state). Classic mode is unchanged. The concrete-type ButtonAdapter casts are dropped so the delegated adapter can be the shared ButtonDarkModeAdapter.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The Appearance.ToggleSwitch renderer placed the switch based on TextAlign, so the default (MiddleLeft) drew the switch on the right. Drive placement from CheckAlign instead: left/center-aligned values (including the MiddleLeft default) put the switch on the left with the caption on the right, and right-aligned values put it on the right. Vertical centering is unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Introduce EffectiveVisualStylesMode to clamp visual styles to Classic when Windows High Contrast is active, ensuring consistent rendering and accessibility.

Update all controls to use this property for rendering and CreateParams decisions.

* Override Form.OnSystemColorsChanged to handle High Contrast transitions by recreating handles as needed. Remove VisualStylesMode.LatestPreview and update related logic.

* Expose EffectiveVisualStylesMode to owner-drawn button adapters for correct renderer selection.
Rewrite the write-once application default test to no longer reference the
removed VisualStylesMode.LatestPreview member. The test now uses Net11 as the
established (write-twice-with-same-value) mode and Latest as the differing
value that must throw. Also drop stale LatestPreview mentions from the
validation comments in Application.SetDefaultVisualStylesMode and
Control.VisualStylesMode.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 41e90924-3241-42a8-9556-71e100be7e59
Align VisualStylesMode with the other ambient properties (BackColor, Cursor,
Font, ForeColor, RightToLeft), which are all public virtual. Making it virtual
allows derived controls to transform the ambient value that children observe
through ParentInternal.VisualStylesMode. The property is still unshipped, so
this only updates the PublicAPI.Unshipped.txt entries.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 41e90924-3241-42a8-9556-71e100be7e59
Override the now-virtual Control.VisualStylesMode in PropertyGrid to always
return VisualStylesMode.Classic. The editing controls hosted inside the grid
read the ambient VisualStylesMode from their parent chain; because the property
is virtual, they resolve to Classic and never switch to a modern renderer whose
frame/glyph metrics would not line up with the grid's fixed layout.

The setter stores the requested value in a backing field for potential future
use but currently has no effect, so setting Net11/Latest is a genuine no-op.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 41e90924-3241-42a8-9556-71e100be7e59
RichEdit (MSFTEDIT) does not send the WM_CTLCOLOR messages a plain EDIT control
uses to lazily trigger the modern Visual Styles client-area carve, so the carve
never ran and Padding had no effect. RichEdit also reserves its own border and
scrollbar space during WM_NCCALCSIZE, so the managed carve must be applied on
top of the native result rather than the raw proposed window rectangle.

- TextBoxBase: extract the carve trigger into RecalculateVisualStylesClientArea
  so it can be re-provoked, add the ReservesNativeNonClientArea hook so
  WmNcCalcSize runs the default handler first for such controls, and re-provoke
  the carve from OnPaddingChanged so runtime Padding changes apply.
- RichTextBox: opt into ReservesNativeNonClientArea, return an empty
  GetScrollBarPadding (RichEdit already reserves the scrollbars), and trigger the
  carve explicitly in OnHandleCreated since WM_CTLCOLOR never arrives.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 41e90924-3241-42a8-9556-71e100be7e59
KlausLoeffelmann and others added 8 commits July 18, 2026 01:27
Keep the branch 01 and branch 05 API declarations as a unique union after applying the integration-tested VisualStyles patch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a909fa48-8991-4d3a-8b90-617a4c026200
Paint rounded cutouts from the real parent surface, refresh live visual-style changes, correct TextBox and UpDown geometry, normalize rounded paths, and improve Popup sizing and motion.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a909fa48-8991-4d3a-8b90-617a4c026200
* Add a bit of formatting/refactoring while reviewing.
Paint parent content beneath antialiased chrome, reduce TextBox and UpDown sizing, and cover native border suppression.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 225d4d4c-7dd7-46f1-9406-b30ff07bd8b5
- Refactored and enhanced modern button rendering for .NET 11+ visual styles, including FlatStyle.Standard, FlatStyle.Flat, and FlatStyle.Popup.
- Improved image and text layout accuracy in ButtonBaseAdapter and ButtonDarkModeAdapter, with new properties for word wrapping, image clipping, and preferred size insets.
- Modern renderers now select automatic foreground colors to ensure WCAG-compliant contrast, adding outlines if needed.
- Popup button palette logic tracks bowl extremes for better contrast.
- ButtonBase and CheckBox reset animators on system color changes.
- Preferred size calculations now use renderer metrics.
- Consolidated painting logic in ButtonDarkModeAdapter.
- Added methods for content bounds and chrome size in PopupButtonKeyCapRenderer.
- Expanded tests for layout, preferred size, color contrast, and system color changes.
- Updated internal APIs and test helpers to support these improvements.
- Use Windows accent color for CheckBox/RadioButton glyphs by default, with high contrast support and cache invalidation on system color changes.
- Animate hover/focus states independently for CheckBox, RadioButton, and ToggleSwitch; add new animation channels and blending logic.
- ToggleSwitch animates thumb growth on hover, uses accent color for "on" state, and improves DPI/font scaling geometry.
- FlatButtonAppearance returns automatic state colors only for non-Popup styles; Popup respects explicit values.
- Update TextBoxBase geometry constants (e.g., corner radius to 15), use accent color for focus unless in high contrast.
- Add and update tests for accent color, animation, geometry, and accessibility.
- Refactor and clean up code, adding helpers for color blending, geometry, and animation state management.
Exclude live native scrollbar rectangles from modern non-client chrome blits.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9c3dc32b-7202-48c4-b0c7-f40a0a681ee2
Clear the residual native edit edge, animate the clipped rounded focus indicator, and expose padding consistently on up-down controls.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 33fa13dc-4960-4c84-a4fb-d1ab91741b73
@KlausLoeffelmann
KlausLoeffelmann force-pushed the Net11Api_05_VisualStylesMode branch from 264f9c2 to d5ecf87 Compare July 18, 2026 08:27
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 27022e2a-9eb8-4f58-9bfa-e79ca0d6c559
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 27022e2a-9eb8-4f58-9bfa-e79ca0d6c559
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 27022e2a-9eb8-4f58-9bfa-e79ca0d6c559
Keep the existing flat dark-mode renderer for Standard buttons in Classic mode. Net11 continues to use the modern renderer without changing legacy dark-mode geometry or separation.

Fixes dotnet#14764

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c352332b-4b81-4492-bcfc-9dec524c27c9
Use ParentBackgroundRenderer for modern CheckBox and RadioButton surfaces so themed and transparent containers, including TabPage, are painted instead of being cleared to an ambient color value.

Fixes dotnet#14759

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c352332b-4b81-4492-bcfc-9dec524c27c9
Render disabled captions without legacy relief and derive a muted color that keeps at least 3:1 contrast against the actual surface. Share the policy across modern buttons, glyph controls, toggle switches, and popup key caps while retaining GrayText as the High Contrast fallback.

Fixes dotnet#14760

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c352332b-4b81-4492-bcfc-9dec524c27c9
Document that ToggleSwitch has no effect in Classic or Disabled mode and that later visual-style versions remain control- and state-specific opt-in boundaries.

Addresses dotnet#14758

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c352332b-4b81-4492-bcfc-9dec524c27c9
Separate background and foreground image painting so modern Button, CheckBox, RadioButton, and popup renderers can preserve the correct z-order. BackgroundImageLayout and RTL positioning now flow through ControlPaint in light and dark Net11 rendering while High Contrast continues to suppress decorative images.

Fixes dotnet#14753

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c352332b-4b81-4492-bcfc-9dec524c27c9
Gate the animated key-cap on the effective Net11 visual style and restore a dedicated dark Popup renderer for Classic and High Contrast fallback paths. Classic popup sizing now uses the legacy adapter metrics again.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c352332b-4b81-4492-bcfc-9dec524c27c9
Apply disabled-text contrast to explicit foreground colors, paint rounded Classic popup corners over the real parent surface, and clip BackgroundImage content inside popup chrome and renderer content bounds.

Follow-up for dotnet#14753 and dotnet#14760

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c352332b-4b81-4492-bcfc-9dec524c27c9
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 24d81626-c337-40c8-a515-393ee8e9827d
Move modern TextBox and UpDown chrome constants into a shared internal source so subsequent renderers use one DPI-independent metric family.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 24d81626-c337-40c8-a515-393ee8e9827d
Add mode-gated card, outline, and header-band renderers with shared layout metrics, cached scaled captions, text-scale relayout, and effective-mode UIA heading semantics. Keep FlatStyle.System native.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 24d81626-c337-40c8-a515-393ee8e9827d
Route Net11 Standard, Flat, and Popup styles through a DPI-aware WinForms adapter, share TextBox field metrics, align native selection heights, and round Win11 dropdowns while preserving System and High Contrast paths.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 24d81626-c337-40c8-a515-393ee8e9827d
Keep modern toggle switches owner-drawn when FlatStyle.System is selected and use control bounds instead of requesting an unsupported native adapter. Cover every FlatStyle, Appearance, and VisualStylesMode interaction.

Fixes dotnet#14754

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 24d81626-c337-40c8-a515-393ee8e9827d
Base ShouldSerializeVisualStylesMode on the raw PropertyStore entry so Inherit emits no CodeDOM while explicit values round-trip through designer serialization.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 24d81626-c337-40c8-a515-393ee8e9827d
Move affected property contracts into partial declarations and add adaptive-layout guidance for metric growth, fixed-bounds editors, GroupBox content geometry, and aligned TextBox/ComboBox rows.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 24d81626-c337-40c8-a515-393ee8e9827d
Apply native selection-field height overrides only while modern metrics are active, or while restoring a field that previously used them, so classic owner-drawn item bounds remain unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 24d81626-c337-40c8-a515-393ee8e9827d
Assert the fixed non-owner-drawn mouse-over geometry instead of retaining the previous unsupported-adapter exception expectation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 24d81626-c337-40c8-a515-393ee8e9827d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment