Skip to content

Fix Issue 14793: ToolStripTextBox renders incorrectly when hosted in MenuStrip - #14873

Draft
SimonZhao888 wants to merge 1 commit into
dotnet:mainfrom
SimonZhao888:Fix_Issue_14793
Draft

Fix Issue 14793: ToolStripTextBox renders incorrectly when hosted in MenuStrip#14873
SimonZhao888 wants to merge 1 commit into
dotnet:mainfrom
SimonZhao888:Fix_Issue_14793

Conversation

@SimonZhao888

@SimonZhao888 SimonZhao888 commented Aug 11, 2026

Copy link
Copy Markdown
Member

Fixes #14793

Root Cause

When a ToolStripControlHost hosts a control (such as a ToolStripTextBox or ToolStripComboBox), the control's own VisualStylesMode can still utilize the .NET 11 modern rendering path; however, the rendering models for the non-client areas and borders of the ToolStrip/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

  • Added a policy within ToolStripControlHost:
    • Once a control is hosted in a ToolStrip or MenuStrip, if its VisualStylesMode is set to a modern mode (such as Net11, Latest, or Inherit), it is forced to Classic mode.
    • If the control is set to Net11 while in the hosted state, it is immediately reverted to Classic.
    • The original requested value is restored after the control is removed from the host (to avoid permanently altering the control's state).
  • Comments for Control.VisualStylesMode and VisualStylesMode.Net11 explicitly state that this mode does not apply to ToolStripControlHost scenarios.
  • Added unit tests (in ToolStripControlHostTests) to provide coverage:

Customer Impact

When using Dark Mode with VisualStylesMode=Net11, applications utilizing ToolStripControlHost exhibit 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 under Professional or ManagerRenderMode.
For menus or toolbars relying on ToolStripTextBox or ToolStripComboBox, this is a highly visible issue that directly impacts the end-user experience.

Regression?

  • No

Risk

  • Mini

Screenshots

Before

image

After

image image

Test methodology

  • Manually
  • Automated test cases

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 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 ToolStripControlHost to clamp hosted controls’ VisualStylesMode to Classic, and restores the prior requested mode when unhosted.
  • Updates API documentation to clarify VisualStylesMode.Net11 (and Control.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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

draft draft PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ToolStripTextBox renders incorrectly when hosted in MenuStrip

2 participants