Fix Issue 14793: ToolStripTextBox renders incorrectly when hosted in MenuStrip - #14873
Draft
SimonZhao888 wants to merge 1 commit into
Draft
Fix Issue 14793: ToolStripTextBox renders incorrectly when hosted in MenuStrip#14873SimonZhao888 wants to merge 1 commit into
SimonZhao888 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses WinForms rendering artifacts that occur when controls hosted by ToolStripControlHost (notably ToolStripTextBox in MenuStrip) use modern VisualStylesMode rendering that conflicts with ToolStrip/MenuStrip border/non-client rendering.
Changes:
- Enforces a hosting policy in
ToolStripControlHostto clamp hosted controls’VisualStylesModetoClassic, and restores the prior requested mode when unhosted. - Updates API documentation to clarify
VisualStylesMode.Net11(andControl.VisualStylesMode) isn’t applied for ToolStrip-hosted controls. - Adds unit tests validating the forcing/restoration behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripControlHost.cs | Implements the hosted-control VisualStylesMode clamp/restoration policy and hooks VisualStylesModeChanged. |
| src/System.Windows.Forms/System/Windows/Forms/VisualStylesMode.cs | Documents that Net11 doesn’t apply for controls hosted via ToolStripControlHost. |
| src/System.Windows.Forms/System/Windows/Forms/Control.VisualStylesMode.Docs.cs | Adds docs clarifying the setting isn’t applied for ToolStripControlHost scenarios. |
| src/test/unit/System.Windows.Forms/System/Windows/Forms/ToolStripControlHostTests.cs | Adds unit tests for forced Classic behavior and restore-after-removal behavior. |
| src/System.Windows.Forms/PublicAPI.Unshipped.txt | Tracks the new ToolStripControlHost.OnOwnerChanged override in public API surface. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+582
to
+590
| private void HandleVisualStylesModeChanged(object? sender, EventArgs e) | ||
| { | ||
| if (_isUpdatingHostedControlVisualStylesMode) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| ApplyHostedControlVisualStylesModePolicy(); | ||
| } |
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 #14793
Root Cause
When a
ToolStripControlHosthosts a control (such as aToolStripTextBoxorToolStripComboBox), the control's ownVisualStylesModecan still utilize the .NET 11 modern rendering path; however, the rendering models for the non-client areas and borders of theToolStrip/MenuStrip(especially when not using the System renderer) do not align with those of the hosted control. This results in rendering pipeline incompatibilities, leading to artifacts such as light-colored blocks or incorrectly drawn borders.Proposed changes
Customer Impact
When using Dark Mode with
VisualStylesMode=Net11, applications utilizingToolStripControlHostexhibit noticeable UI flaws—such as anomalous borders or backgrounds—that compromise interface consistency and a professional appearance. While functionality generally remains intact, visual quality suffers, and the issue is more easily reproduced underProfessionalorManagerRenderMode.For menus or toolbars relying on
ToolStripTextBoxorToolStripComboBox, this is a highly visible issue that directly impacts the end-user experience.Regression?
Risk
Screenshots
Before
After
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow