Skip to content

[NO MERGE] Add versioned .NET 11 Visual Styles#14737

Open
KlausLoeffelmann wants to merge 84 commits into
dotnet:feature/11.0from
KlausLoeffelmann:Net11Api_05_VisualStylesMode
Open

[NO MERGE] Add versioned .NET 11 Visual Styles#14737
KlausLoeffelmann wants to merge 84 commits into
dotnet:feature/11.0from
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.


⚠️ NO MERGE (yet). This PR belongs to a stacked series of .NET 11 API PRs and does not compile on its own. The PRs must be merged in this order (each builds on the previous):

#14733#14734#14735#14737

(Net11Api_04 / #14736 is intentionally excluded from this sequence for now.) Please do not merge this PR until the preceding PRs in the sequence have been merged.

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 10 commits July 19, 2026 16:51
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
Render Standard as a borderless rectangular surface, use an accent outline for Flat and an accent header for Popup, and select real installed Semibold faces without mutating ambient fonts. Align caption and content metrics with Padding and preserve the existing visual-settings tracker cleanup.

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

Copilot-Session: 24d81626-c337-40c8-a515-393ee8e9827d
Reactivate designer serialization for the shipped Padding property, add a one-pixel framework inset, render rounded Standard and Popup frames plus a square Flat frame, and keep native edit/list content aligned across DPI, style, and layout changes.

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

Copilot-Session: 24d81626-c337-40c8-a515-393ee8e9827d
Accept the native System-style handle recreation's platform-dependent zero-or-one invalidation while retaining exact expectations for owner-drawn styles.

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

Copilot-Session: 24d81626-c337-40c8-a515-393ee8e9827d
…on, no flicker, classic-safe)

Squashed from Net11/VisualStylesMode-Fixes onto the 05 VisualStylesMode base
branch (the source of truth for VisualStyles). Includes:

- Ambient visual-styles layout fix (VisualStylesMode stored/reported as Inherit;
  EffectiveVisualStylesMode via GetEffectiveVisualStylesMode(IsHighContrast)).
- Centralized modern ComboBox native layout (per-handle baseline, absolute
  target state, idempotent applier) and the modern renderer refactor.
- Modern ComboBox: WM_NCCALCSIZE unifies the field over the drop-down button;
  WM_NCHITTEST->HTCLIENT plus a press/release hit-test makes the button open the
  list; double-buffered paint removes adorner flicker; wider button and edit
  window inset so the edit child clears the rounded arcs.
- New Control.VisualStylesModeChangeImpact.Recreate: ComboBox returns it when
  crossing the modern/classic boundary so the handle is recreated and classic
  behaves exactly as before. WM_NCCALCSIZE is gated off for Simple combos.

The 05 base branch is a main-based feature slice and does not compile on its own
(it references SystemVisualSettings from a sibling base); validation happens in
the integration build.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 64d20bbb-13df-4e59-8bcc-c307909b03f8
The modern (Net11+) UpDownBase content inset (ModernContentInset) used a flat 1px border-thickness term, so its edit and side-by-side buttons sat one pixel tighter inside the frame than a modern TextBoxBase (which uses the per-border-style border padding from ModernControlVisualStyles.GetFieldPadding). Switch to the same per-border-style constants so the internal padding matches: Fixed3D 3->4, None 2->3, FixedSingle unchanged at 3.

Also document every metric in ModernControlVisualStyles with an XML summary, and update the UpDownBase modern-geometry tests to the new default (Fixed3D) inset of 4.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 1ba7f56)
Follows the API Review board rename of SystemVisualSettingsCategories.Animations
to ClientAreaAnimations (enum owned by the New Application API base).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 64d20bbb-13df-4e59-8bcc-c307909b03f8
@KlausLoeffelmann
KlausLoeffelmann changed the base branch from main to feature/11.0 July 22, 2026 23:01
@KlausLoeffelmann KlausLoeffelmann changed the title Add versioned .NET 11 Visual Styles [NO MERGE] Add versioned .NET 11 Visual Styles Jul 22, 2026
KlausLoeffelmann and others added 16 commits July 22, 2026 21:32
The modern VisualStyles rounded chrome (TextBox, UpDown, ComboBox, GroupBox)
masks/clips its corners with a Region, which cannot be anti-aliased and leaves
jagged pixels just outside the anti-aliased border. Add a shared
ParentBackgroundRenderer.PaintRoundedBorderRegionMitigation helper that traces
a 2px line in the parent background color immediately outside each rounded
border, blending the artifact into the parent. Wire it into TextBoxBase,
UpDownBase, ComboBox.ModernComboAdapter and GroupBox.Modern.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 19883d86-6d5f-4d51-94c2-81d0bf3fc3ff
Branch 05's modern VisualStyles renderer tests (ComboBox, GroupBox, CheckBox
ToggleSwitch, GroupBox accessibility) use SystemVisualSettingsTestScope to make
system visual settings deterministic. The helper wraps branch 01's
SystemVisualSettingsTracker.ResetForTesting and was previously only added during
integration; define it in branch 05 where its consumers live.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 19883d86-6d5f-4d51-94c2-81d0bf3fc3ff
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 27022e2a-9eb8-4f58-9bfa-e79ca0d6c559
OnNcPaint already computes focusBandHeight via GetVisualStylesFocusBandHeight();
the rounded focus-indicator call referenced a non-existent VisualStylesFocusBandHeight
constant. Use the computed focusBandHeight value (already scaled) instead. This
removes an integration-time repair so branch 05 is self-consistent.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 19883d86-6d5f-4d51-94c2-81d0bf3fc3ff
The modern VisualStyles rendering (ComboBox/GroupBox/TextBox) triggers layout
via LayoutTransaction.DoLayout(..., PropertyNames.SystemVisualSettings), but the
key was only introduced during integration. Define it alongside VisualStylesMode
so branch 05 is self-contained.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 19883d86-6d5f-4d51-94c2-81d0bf3fc3ff
…lper

TextBoxBaseTests invokes parent.RaiseSystemVisualSettingsChanged(...) on a
VisualStylesModePanel, but the helper only exposed the raiser on the TextBox
subclass. Add the matching seam to VisualStylesModePanel so the parent-driven
settings-change tests compile.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 19883d86-6d5f-4d51-94c2-81d0bf3fc3ff
The modern ComboBox painted its field surface and DropDownList selection
background with the control's BackColor regardless of Enabled, so a disabled
ComboBox still showed its full custom BackColor/ForeColor. The button, border,
and text already handled the disabled state; the surface fill did not.

Add GetEffectiveFieldColor, which mutes the background (matching the existing
disabled button/GroupBox treatment) when the control is disabled, and use it
for the field surface and the DropDownList selection background.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 64d20bbb-13df-4e59-8bcc-c307909b03f8
…et#14779)

The modern GroupBox renderers fill an opaque body surface (DrawModernCard fills
frameBounds; DrawModernPopup fills the rounded body path), which painted over
the BackgroundImage drawn by OnPaintBackground, so the image was invisible for
FlatStyle Standard and Popup in VisualStylesMode.Net11.

Composite the BackgroundImage back over the surface via a new
PaintModernBackgroundImage helper (transparent back color so the surface tint
is preserved around non-tiling layouts), clipped to the body area (and to the
rounded frame path for Popup).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 64d20bbb-13df-4e59-8bcc-c307909b03f8
Make Padding affect only the child content area (DisplayRectangle), never the
rendered adornments or caption text, and correct each FlatStyle's layout.

- Padding no longer moves the caption text. Exception: Standard and Popup shift
  the caption horizontally by Padding.Left (LTR) / Padding.Right (RTL); the
  caption never moves vertically and Flat ignores Padding for text.
- Standard (card): drop the internal horizontal and bottom content insets, so a
  docked child with Padding = 0 fills the entire card. DisplayRectangle reserves
  only the caption band plus its gap at the top.
- Flat (outline): run the top border line along the caption text baseline (was
  the caption vertical middle), indent the caption by the corner radius, and set
  the top content inset to the font descent + 1px leeway so content clears the
  descenders. Left/right/bottom sit just inside the border.
- Popup: 2px system inset on left/right/bottom and a 0px top gap so content is
  flush with the accent header rectangle; caption uses the Standard alignment
  rule on top of the header's horizontal padding.
- Add GetModernCaptionMetrics (device-pixel ascent/descent from the caption
  font family metrics) plus GroupBoxPopupContentInset and
  GroupBoxFlatBaselineLeeway constants.

Updated the modern DisplayRectangle unit test to the new per-style formulas and
added coverage for the zero-padding card fill, the Flat baseline top inset, the
Popup insets, and Padding not moving the caption vertically. All 968 GroupBox
tests pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 64d20bbb-13df-4e59-8bcc-c307909b03f8
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 86cc3454-1c71-4d7f-a766-231b55099101
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 86cc3454-1c71-4d7f-a766-231b55099101
Preserve owner-drawn DropDownList content and validate recreated handles, child-bound padding, final chrome insets, and antialiased colors.

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

Copilot-Session: 86cc3454-1c71-4d7f-a766-231b55099101
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 86cc3454-1c71-4d7f-a766-231b55099101
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 86cc3454-1c71-4d7f-a766-231b55099101
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 86cc3454-1c71-4d7f-a766-231b55099101
Share Popup caption padding with Standard, lower Flat captions by the logical stroke, and make Flat border gaps symmetric around measured text.

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

Copilot-Session: 86cc3454-1c71-4d7f-a766-231b55099101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment