Repository navigation
Description
Rationale
WinForms developers commonly perform bursts of UI mutations: adding controls or items,
changing style and size-affecting properties, or showing a form whose first complete frame
is not ready when its HWND becomes visible. Today applications combine control-specific
BeginUpdate / EndUpdate, SuspendLayout / ResumeLayout, hand-written
WM_SETREDRAW, and DWM/window workarounds.
These techniques are inconsistent and easy to misbalance. Painting-only suspension also
misses a common requirement: style changes often invalidate preferred sizes and require
layout to be recalculated before the control tree is repainted.
This proposal provides:
- a ref-counted painting suspension contract and await-capable scope;
- optional layout suspension for the target, the complete existing control tree, or
predicate-selected controls; and - deferred top-level form reveal to reduce initial default-background flash, especially
in dark-mode applications.
The goal is not to make the layout engine itself faster. The goal is to collapse avoidable
intermediate layout and paint work and reveal the final state in a predictable order.
API Proposal
namespace System.Windows.Forms;
public interface ISupportSuspendPainting
{
void BeginSuspendPainting();
void EndSuspendPainting();
}
public enum LayoutSuspendTraversal
{
None = 0,
TopLevelOnly = 1,
Traverse = 2,
}namespace System.Windows.Forms;
public sealed class SuspendPaintingScope : IDisposable
{
public SuspendPaintingScope(ISupportSuspendPainting? target);
public void Dispose();
}
public static class ControlMutationExtensions
{
public static SuspendPaintingScope SuspendPainting(
this ISupportSuspendPainting target);
public static SuspendPaintingScope SuspendPainting(
this ISupportSuspendPainting target,
LayoutSuspendTraversal layoutSuspendTraversal);
public static SuspendPaintingScope SuspendPainting(
this ISupportSuspendPainting target,
Func<Control, bool> suspendLayoutContainerFilter);
}namespace System.Windows.Forms;
public partial class Control : ISupportSuspendPainting
{
void ISupportSuspendPainting.BeginSuspendPainting()
=> BeginSuspendPaintingCore();
void ISupportSuspendPainting.EndSuspendPainting()
=> EndSuspendPaintingCore();
protected virtual void BeginSuspendPaintingCore();
protected virtual void EndSuspendPaintingCore();
}namespace System.Windows.Forms;
public partial class ListView
{
protected override void BeginSuspendPaintingCore();
protected override void EndSuspendPaintingCore();
}
public partial class ListBox
{
protected override void BeginSuspendPaintingCore();
protected override void EndSuspendPaintingCore();
}
public partial class ComboBox
{
protected override void BeginSuspendPaintingCore();
protected override void EndSuspendPaintingCore();
}
public partial class TreeView
{
protected override void BeginSuspendPaintingCore();
protected override void EndSuspendPaintingCore();
}
public partial class RichTextBox
{
protected override void BeginSuspendPaintingCore();
protected override void EndSuspendPaintingCore();
}namespace System.Windows.Forms;
public enum FormRevealMode
{
Inherit = -1,
Classic = 0,
Deferred = 1,
}
public partial class Form
{
public virtual FormRevealMode FormRevealMode { get; set; }
}
public partial class Application
{
public static FormRevealMode DefaultFormRevealMode { get; }
public static void SetDefaultFormRevealMode(FormRevealMode mode);
public static bool IsFormRevealDeferred { get; }
}Namespace Microsoft.VisualBasic.ApplicationServices
Public Class ApplyApplicationDefaultsEventArgs
Inherits EventArgs
Public Property FormRevealMode As FormRevealMode
End Class
End NamespaceAPI Usage
// Suspend painting only.
using (listView.SuspendPainting())
{
listView.Items.Clear();
listView.Items.AddRange(CreateItems());
}// Suspend layout for the panel and its complete existing control tree.
using (buttonPanel.SuspendPainting(LayoutSuspendTraversal.Traverse))
{
foreach (Button button in buttonPanel.Controls.OfType<Button>())
{
button.Font = updatedFont;
button.Text = GetUpdatedText(button);
}
}// Suspend layout only for containers selected by the application. Returning false
// skips that control but traversal continues into its descendants.
using (root.SuspendPainting(
control => control is TableLayoutPanel or FlowLayoutPanel or UserControl))
{
ApplyApplicationStyle(root);
}// SuspendPaintingScope is a sealed class, so it can span an await.
private async void reloadButton_Click(object? sender, EventArgs e)
{
using SuspendPaintingScope scope =
listView.SuspendPainting(LayoutSuspendTraversal.TopLevelOnly);
listView.Items.Clear();
List<ListViewItem> items = await LoadItemsAsync();
listView.Items.AddRange([.. items]);
}// Dark mode resolves the inherited reveal mode to Deferred by default.
Application.SetColorMode(SystemColorMode.Dark);
Application.Run(new MainForm());// Opt one form out of deferred reveal.
public partial class SplashScreenForm : Form
{
public SplashScreenForm()
{
InitializeComponent();
FormRevealMode = FormRevealMode.Classic;
}
}Alternative Designs
A separate relocation-suspension interface and scope
The previous revision exposed ISupportSuspendRelocation,
SuspendRelocationScope, and SuspendRelocation(). That API was too broad and made a
second manually balanced suspension mechanism public. The common scenario is specifically
to complete layout before repainting after a visual mutation. Integrating controlled layout
suspension into the painting scope gives the operation one lifetime and one deterministic
resume order.
Only one traversal policy
Always traversing is simple but can be unnecessarily expensive for large trees. Suspending
only the target misses nested layout containers. The enum handles common policies, while the
predicate overload allows applications to select known layout containers without pruning
their descendants.
Suspend only controls that currently have children
This misses the important case where the mutation adds the first child to an empty
container. Selected controls are therefore suspended regardless of their current child
count.
readonly ref struct scope
A stack-only scope makes accidental lifetime extension impossible, but it cannot span
await. Awaiting data while painting remains suspended is a legitimate WinForms UI
scenario, so the proposal uses a sealed IDisposable class and accepts one allocation per
mutation scope.
Public virtual Begin/End methods directly on Control
Explicit interface implementation keeps manually balanced methods out of normal
Control IntelliSense. Protected core hooks still allow built-in and derived controls to
route suspension through the correct native mechanism.
Use only SuspendLayout
SuspendLayout avoids layout computation but does not suppress painting. It is necessary
for some mutations but is not sufficient for flicker-free updates.
Risks
- The control selection is snapshotted when the scope starts. Controls added later are
covered by their selected parent's suspended layout but do not receive an independently
balanced suspension. Traverseis O(number of controls) and holds references to selected controls until the
scope is disposed.- Predicate code runs synchronously before any suspension begins. Exceptions propagate and
leave painting/layout untouched. - Layout is suspended root-to-leaf and resumed deepest-first. Every selected node resumes
its own layout, which can be more work than a single top-level layout but preserves each
container's normalResumeLayoutsemantics. - Layout-aware overloads require an actual
Control; custom non-Control
ISupportSuspendPaintingimplementations can use the painting-only overload. WM_SETREDRAWsuppresses HWND painting but does not make arbitrary custom drawing atomic.- Existing control-specific
BeginUpdate/EndUpdateAPIs retain their existing behavior.
The painting scope defers one recursive invalidation until the final nested scope resumes. - Scope disposal can surface exceptions from layout or custom suspension hooks. Cleanup
continues so scope-owned suspension counts are not silently leaked. FormRevealMode.Deferreddepends on DWM support and must remain inert on unsupported
systems and unsupported window kinds.- Deferred reveal reduces default-background flash, but deeply nested controls can still
update visibly after the form is revealed. - All APIs are UI-thread-oriented and do not make WinForms controls thread-safe.
Will this feature affect UI controls?
Yes. Control and the selected built-in controls implement painting suspension.
Layout-aware scopes temporarily call the existing SuspendLayout / ResumeLayout
mechanism on selected controls, then recursively invalidate after layout has completed.
They do not change final layout results, accessibility names/roles, localization, or
designer serialization.
FormRevealMode.Deferred affects top-level form startup presentation. It should preserve
accessibility/UIA object creation and not hide forms from accessibility clients longer than
necessary. FormRevealMode remains an ambient, designer-serializable property with
Inherit as its reset sentinel.
Revised after implementation testing: removed the separate relocation-suspension
interface and scope. Layout suspension is now an optional, controlled part of
SuspendPainting, with enum-based and predicate-based control-tree selection. The
implementation was validated onNet11/Integration-2in
KlausLoeffelmann/winforms@a62e1e5.Earlier revisions renamed
FormAppearanceModetoFormRevealMode, removed the
DeferLocationChange/DeferWindowPosbatching sub-feature (tracked separately at
KlausLoeffelmann#12), made the painting scope a sealed class so it can span
await, and introduced explicit interface implementation with protected core hooks.
This proposal is tracked alongside the other .NET 11 APIs in #14694.
Status Checklist
- API proposal has
api-suggestionlabel - Background, API Proposal, API Usage, and Risks sections are complete
- API shape has been discussed with the team
- Review the issue for compatibility with what the API review board expects
- Change label to
api-ready-for-review - If late in the release cycle, also add the
blockinglabel to expedite the review appointment - API review completed — label changed to
api-approved
Activity
[-]Add APIs for performance improved, flicker-free WinForms UI mutation[/-][+][.NET 11 API Proposal] Add APIs for performance improved, flicker-free WinForms UI mutation[/+]Remove DeferLocationChange; make suspend-mutation hooks explicit-inte…
Rename FormAppearanceMode to FormRevealMode with Inherit ambient sent…
Wire FormRevealMode into the VB Application Framework
Remove DeferLocationChange; make suspend-mutation hooks explicit-inte…
Rename FormAppearanceMode to FormRevealMode with Inherit ambient sent…
Wire FormRevealMode into the VB Application Framework
Remove DeferLocationChange; make suspend-mutation hooks explicit-inte…
Rename FormAppearanceMode to FormRevealMode with Inherit ambient sent…
Wire FormRevealMode into the VB Application Framework
Remove DeferLocationChange; make suspend-mutation hooks explicit-inte…
26 remaining items
Remove DeferLocationChange; make suspend-mutation hooks explicit-inte…
Rename FormAppearanceMode to FormRevealMode with Inherit ambient sent…
Wire FormRevealMode into the VB Application Framework
Remove DeferLocationChange; make suspend-mutation hooks explicit-inte…
Rename FormAppearanceMode to FormRevealMode with Inherit ambient sent…
Wire FormRevealMode into the VB Application Framework
.NET 11: integrate application, rendering, and visual styles APIs (#1…
.NET 11: integrate application, rendering, and visual styles APIs (#1…
KlausLoeffelmann commentedon Jul 29, 2026
Merged into main and Preview 7.