Skip to content

Add flicker-free UI mutation APIs#14735

Open
KlausLoeffelmann wants to merge 11 commits into
dotnet:mainfrom
KlausLoeffelmann:Net11Api_03_ImproveControlRendering
Open

Add flicker-free UI mutation APIs#14735
KlausLoeffelmann wants to merge 11 commits into
dotnet:mainfrom
KlausLoeffelmann:Net11Api_03_ImproveControlRendering

Conversation

@KlausLoeffelmann

@KlausLoeffelmann KlausLoeffelmann commented Jul 14, 2026

Copy link
Copy Markdown
Member

Closes #14585.
Contributes to #14694.

  • Adds composable painting and relocation suspension interfaces and disposable scopes.
  • Implements control-specific suspension hooks while preserving nested and handle-recreation semantics.
  • Adds ambient FormRevealMode and application-default support to reduce initial form flash.
  • Wires the feature through the Visual Basic Application Framework.
  • Includes focused tests for suspension balancing, async-safe scopes, form reveal behavior, and handle lifetimes.
Microsoft Reviewers: Open in CodeFlow

KlausLoeffelmann and others added 11 commits July 18, 2026 01:26
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>
Implements suspend painting and relocation scopes, deferred child positioning, and form appearance mode infrastructure for .NET 11.

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

Splits DeferLocationChange out of this branch entirely (postponed pending an
anchor-layout-engine integration fix; tracked separately in
#12) and reworks ISupportSuspendPainting /
ISupportSuspendRelocation on Control to match the final API shape agreed in
dotnet#14585:

- Control implements ISupportSuspendPainting/ISupportSuspendRelocation via
  explicit interface implementation instead of public virtual methods, so the
  manual Begin/End pair does not become the primary IntelliSense surface on
  every Control-derived type. Protected virtual BeginSuspendPaintingCore() /
  EndSuspendPaintingCore() / BeginSuspendRelocationCore() /
  EndSuspendRelocationCore() are the new override points.
- ListView, ListBox, ComboBox, TreeView, RichTextBox override the ...Core()
  hooks instead of the old public virtual methods, still routing through
  their existing BeginUpdate/EndUpdate.
- SuspendPaintingScope and SuspendRelocationScope change from
  readonly ref struct to sealed class : IDisposable, so the scope can span an
  await in an asynchronous UI event handler (a ref struct cannot be hoisted
  into an async state machine - this was the flagship usage scenario in the
  original API proposal, and it did not compile against the ref struct
  version). Dispose is idempotent.
- Deletes DeferLocationChangeScope.cs and the Control.DeferLocationChange
  overloads entirely.
- Updates/removes tests accordingly; updates PublicAPI.Unshipped.txt.

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

Matches the final API shape agreed in dotnet#14585:

- FormAppearanceMode -> FormRevealMode, adding Inherit = -1 as the ambient
  sentinel (Classic stays the CLR default value 0, matching the
  RightToLeft.Inherit / VisualStylesMode.Inherit precedent for ambient
  enums - the sentinel is a distinct value, not the zero value, so
  default(FormRevealMode) stays conservative).
- Form.FormRevealMode is now a real public virtual, PropertyStore-backed,
  [AmbientValue(Inherit)] property (previously there was no per-Form
  property at all - only the flat, process-wide
  Application.FormAppearanceMode existed). This lets a form such as a splash
  screen opt itself out of deferred reveal without touching the process-wide
  default. Resolution is flat (Form only, no Control-parent-chain): DWM
  cloaking only ever applies to top-level, non-MDI-child windows, so there is
  no hierarchy to walk, unlike VisualStylesMode's genuine control-nesting
  cascade.
- Application.FormAppearanceMode / SetFormAppearanceMode are replaced by
  three members: DefaultFormRevealMode (get; may return the unresolved
  Inherit sentinel, mirroring ColorMode returning the unresolved System
  value), SetDefaultFormRevealMode (freely reassignable, unlike the
  write-once SetDefaultVisualStylesMode - the effective default is derived in
  part from ColorMode/IsDarkModeEnabled, which are themselves mutable for the
  life of the process), and IsFormRevealDeferred (bool; the fully resolved
  answer: Deferred, or Inherit + IsDarkModeEnabled). This also fixes a
  compatibility problem in the original design: the old default was
  unconditionally Deferred whenever SetFormAppearanceMode was never called,
  an opt-out behavior change for every existing app; tying the Inherit
  resolution to dark mode means an app that never touches SystemColorMode
  sees no behavior change, while the scenario the feature exists for
  (dark-mode startup flash) is fixed by default.
- ShouldUseDeferredAppearanceCloak now reads the resolved Form.FormRevealMode
  instead of the old flat Application-only check, so a per-Form override is
  actually honored.
- Adds SR.resx/xlf entries for the new property's designer description.
- Updates/adds tests; updates PublicAPI.Unshipped.txt.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds Microsoft.VisualBasic.ApplicationServices.ApplyApplicationDefaultsEventArgs.FormRevealMode,
following the exact same pattern already established for ColorMode and
HighDpiMode in that class, per dotnet#14585's API Proposal.

WindowsFormsApplicationBase now carries a _formRevealMode shadow field
(defaulting to FormRevealMode.Classic, matching the existing conservative
default for _colorMode) and a protected FormRevealMode property, feeds it
into the ApplyApplicationDefaultsEventArgs constructor alongside
MinimumSplashScreenDisplayTime/HighDpiMode/ColorMode, reads back whatever the
ApplyApplicationDefaults event handler set, and calls
Application.SetDefaultFormRevealMode(_formRevealMode) at the end of
OnInitialize alongside the existing Application.SetColorMode(_colorMode)
call.

This completes work anticipated but never finished in an earlier .NET 9
Visual Styles attempt at this same VB Application Framework extension point
(OnInitialize already carried a comment claiming "We feed the defaults for
HighDpiMode, ColorMode, VisualStylesMode to the EventArgs", but only
HighDpiMode/ColorMode were ever actually wired up).

Updates PublicAPI.Unshipped.txt for Microsoft.VisualBasic.Forms.

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

Copilot-Session: 20883488-cf1e-4ad3-a681-0724e9f16777
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 20883488-cf1e-4ad3-a681-0724e9f16777
Remove the risky relocation API and add controlled layout traversal to painting scopes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9c3dc32b-7202-48c4-b0c7-f40a0a681ee2
@KlausLoeffelmann
KlausLoeffelmann force-pushed the Net11Api_03_ImproveControlRendering branch from 67dd34f to d26d86f Compare July 18, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[.NET 11 API Proposal] Add APIs for performance improved, flicker-free WinForms UI mutation

1 participant