Fix issue 14796: ComboBox with FlatStyle.System renders incorrectly at design time - #14852
Open
SimonZhao888 wants to merge 2 commits into
Open
Fix issue 14796: ComboBox with FlatStyle.System renders incorrectly at design time#14852SimonZhao888 wants to merge 2 commits into
SimonZhao888 wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
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.FlatStylesetter to recreate the handle when theUsesModernComboAdapterstate transitions and a handle already exists. - Update
ComboBox.OnVisualStylesModeChangedto recreate the handle forFlatStyle.Systemwhen a handle exists, preventing stale native layout artifacts across mode changes. - Add regression tests covering handle recreation for (1) modern → system
FlatStyletransitions and (2) classic ↔ Net11 visual style mode transitions while usingFlatStyle.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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
ComboBox.FlatStylesetter, when theUsesModernComboAdapterstate undergoes a transition:RecreateHandle();ApplyModernComboLayout().ComboBox.OnVisualStylesModeChanged, add handle recreation for scenarios involvingFlatStyle.Systemwhere the handle already exists, preventing artifacts from persisting across mode changes.FlatStylefrom "modern" to "System" (with an existing handle);FlatStyle.System(with an existing handle).Customer Impact
FlatStyle.Systemwhile inNet11mode ensures theComboBox(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?
Risk
Screenshots
Before
After
14796-1.mp4
14796-2.mp4
Test methodology
Accessibility testing
Test environment(s)
Microsoft Reviewers: Open in CodeFlow