Skip to content

Fix issue 14796: ComboBox with FlatStyle.System renders incorrectly at design time - #14852

Open
SimonZhao888 wants to merge 2 commits into
dotnet:mainfrom
SimonZhao888:Fix_Issue_14796
Open

Fix issue 14796: ComboBox with FlatStyle.System renders incorrectly at design time#14852
SimonZhao888 wants to merge 2 commits into
dotnet:mainfrom
SimonZhao888:Fix_Issue_14796

Conversation

@SimonZhao888

@SimonZhao888 SimonZhao888 commented Aug 5, 2026

Copy link
Copy Markdown
Member

Fixes #14796

Root Cause

When a ComboBox switches from a modern FlatStyle (Standard, Flat, or Popup) to FlatStyle.System under VisualStylesMode.Net11, or switches across visual-style modes while using FlatStyle.System, the native handle is not reliably recreated. This results in residual geometry or child-window states from the modern rendering path, causing rendering anomalies in the button area within the designer.

Proposed changes

  • In the ComboBox.FlatStyle setter, when the UsesModernComboAdapter state undergoes a transition:
    • If the handle has been created, call RecreateHandle();
    • If not, proceed to call ApplyModernComboLayout().
  • In ComboBox.OnVisualStylesModeChanged, add handle recreation for scenarios involving FlatStyle.System where the handle already exists, preventing artifacts from persisting across mode changes.
  • Add regression tests covering:
    • Switching FlatStyle from "modern" to "System" (with an existing handle);
    • Switching visual style modes while using FlatStyle.System (with an existing handle).

Customer Impact

  • After the fix, switching to FlatStyle.System while in Net11 mode ensures the ComboBox (especially the drop-down button area) renders correctly using native styling, thereby reducing visual glitches and confusion within the designer; the trade-off is an additional handle recreation during this switch (resulting in a minor impact on performance or flickering, which is generally acceptable).

Regression?

  • No

Risk

  • Mini

Screenshots

Before

image

After

14796-1.mp4
14796-2.mp4

Test methodology

  • Manually
  • Automated test cases

Accessibility testing

Test environment(s)

  • 11.0.0-preview.7.26381.103
Microsoft Reviewers: Open in CodeFlow

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 addresses a WinForms designer rendering issue where ComboBox can retain stale native geometry when switching to FlatStyle.System (or changing VisualStylesMode while already in FlatStyle.System) under modern visual styles, by ensuring the native handle is recreated in those transition scenarios.

Changes:

  • Update ComboBox.FlatStyle setter to recreate the handle when the UsesModernComboAdapter state transitions and a handle already exists.
  • Update ComboBox.OnVisualStylesModeChanged to recreate the handle for FlatStyle.System when a handle exists, preventing stale native layout artifacts across mode changes.
  • Add regression tests covering handle recreation for (1) modern → system FlatStyle transitions and (2) classic ↔ Net11 visual style mode transitions while using FlatStyle.System.

Reviewed changes

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

File Description
src/test/unit/System.Windows.Forms/System/Windows/Forms/ComboBoxTests.cs Adds regression tests asserting handle recreation on FlatStyle/VisualStylesMode transitions.
src/System.Windows.Forms/System/Windows/Forms/Controls/ComboBox/ComboBox.Modern.cs Recreates handle on visual style mode changes when FlatStyle.System and handle exists.
src/System.Windows.Forms/System/Windows/Forms/Controls/ComboBox/ComboBox.cs Recreates handle in FlatStyle setter when modern-adapter usage toggles and a handle exists.

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

Comment thread src/System.Windows.Forms/System/Windows/Forms/Controls/ComboBox/ComboBox.cs Outdated
Comment thread src/System.Windows.Forms/System/Windows/Forms/Controls/ComboBox/ComboBox.cs Outdated
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.

ComboBox with FlatStyle.System renders incorrectly at design time

2 participants