Skip to content

Conversation

@SimonZhao888
Copy link
Member

@SimonZhao888 SimonZhao888 commented Jan 26, 2026

Fixes #14094

Proposed changes

  • Ensure hosted controls are only reparented to ToolStrip parents after the parent handle is created, preventing SetParent failures when items overflow.
  • Added a regression test to verify ToolStripControlHost controls with existing handles can move into the overflow drop-down without throwing.

Customer Impact

  • When the form width is reduced to prevent Toolstrip items from displaying, clicking the ToolBar Options no error throws and Toolstrip items show correctly.

Regression?

  • Yes

Risk

-Min

Screenshots

Before

Image

After

Bug14094.mp4

Test methodology

  • Manually

Test environment(s)

  • 11.0.0-alpha.1.25619.109
Microsoft Reviewers: Open in CodeFlow

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Win32Exception when ToolStripControlHost-hosted controls (e.g., ToolStripComboBox/ToolStripProgressBar) move into the overflow drop-down after the form is narrowed, by ensuring the ToolStrip parent has a handle before reparenting hosted controls.

Changes:

  • Update ToolStripControlHost.SyncControlParent() to create the ToolStrip parent handle when the hosted control handle already exists.
  • Add a regression test covering moving hosted controls with existing handles into the overflow drop-down without throwing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripControlHost.cs Ensures the ToolStrip parent handle exists before adding the hosted control to the ToolStrip’s control collection.
src/test/unit/System.Windows.Forms/System/Windows/Forms/ToolStripControlHostTests.cs Adds a regression test intended to reproduce/guard against the overflow reparenting Win32Exception scenario.

Copy link
Member

@LeafShi1 LeafShi1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! The failed tests need to be addressed.

Simon Zhao (BEYONDSOFT CONSULTING INC) added 2 commits January 27, 2026 13:41
@codecov
Copy link

codecov bot commented Jan 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.17980%. Comparing base (86f2d9a) to head (1d3fba0).

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #14244         +/-   ##
===================================================
+ Coverage   77.17712%   77.17980%   +0.00267%     
===================================================
  Files           3279        3279                 
  Lines         645129      645161         +32     
  Branches       47728       47730          +2     
===================================================
+ Hits          497892      497934         +42     
+ Misses        143544      143528         -16     
- Partials        3693        3699          +6     
Flag Coverage Δ
Debug 77.17980% <100.00000%> (+0.00267%) ⬆️
integration 18.98827% <55.55556%> (-0.00054%) ⬇️
production 52.05190% <100.00000%> (+0.00481%) ⬆️
test 97.40497% <100.00000%> (+0.00018%) ⬆️
unit 49.51635% <100.00000%> (+0.02956%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After reducing the form width, clicking the ToolStrip options triggers a Win32Exception error

2 participants