Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix Win32Exception when clicking ToolBar Options after narrowing form width#14104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge3 commits intomain
base:main
Choose a base branch
Loading
fromcopilot/fix-toolstrip-win32exception

Conversation

Copy link
Contributor

CopilotAI commentedDec 4, 2025
edited by SimonZhao888
Loading

Fixes#14094

Proposed changes

  • ModifiedToolStripControlHost.SyncControlParent() to keep hosted controls parented toOwner ToolStrip whenParentInternal is aToolStripDropDown
  • Added unit tests verifying hosted controls don't get added to dropdown's Controls collection

Root cause: WhenToolStripControlHost items (e.g.,ToolStripComboBox,ToolStripProgressBar) move to overflow,SyncControlParent() was adding the hosted control to theToolStripOverflow's Controls collection. When the dropdown shows,CreateControl callsSetParentHandle which fails becauseToolStripDropDown is a TopLevel popup window (DPI awareness/window hierarchy constraints).

// Before: always used ParentInternalReadOnlyControlCollection?newControls=GetControlCollection(ParentInternal);// After: use Owner when ParentInternal is a dropdownToolStrip?targetParent=ParentInternalisToolStripDropDown?Owner:ParentInternal;ReadOnlyControlCollection?newControls=GetControlCollection(targetParent);

Customer Impact

  • UnhandledWin32Exception crashes app when clicking overflow button on narrowed ToolStrip containing control hosts
  • Blocking issue for apps usingToolStripComboBox orToolStripProgressBar in constrained layouts

Regression?

  • No - never worked in .NET Core/.NET 5+; worked in .NET Framework

Risk

  • Low - targeted fix affecting onlyToolStripControlHost parenting when parent is a dropdown

Test methodology

  • Added unit tests for dropdown parenting scenarios
  • Verified hosted control stays in Owner's Controls collection when Parent is ToolStripDropDown

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 0t3vsblobprodcus362.vsblob.vsassets.io
    • Triggering command:/usr/bin/dotnet dotnet restore (dns block)
  • o3svsblobprodcus318.vsblob.vsassets.io
    • Triggering command:/home/REDACTED/work/winforms/winforms/.dotnet/dotnet /home/REDACTED/work/winforms/winforms/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/winforms/winforms/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/winforms/winforms/artifacts/toolset/11.0.0-beta.25602.105.txt rivate.Windows.Core/src/System/V--property=CPUQuota=5% rivate.Windows.Core/src/System/P--property=MemoryHigh=170M rivate.Windows.Ccurl rivate.Windows.C--retry rivate.Windows.C20 rivate.Windows.C--retry-delay (dns block)
    • Triggering command:/usr/bin/dotnet dotnet restore (dns block)
    • Triggering command:/usr/bin/dotnet dotnet build --no-restore (dns block)
  • rcxvsblobprodcus328.vsblob.vsassets.io
    • Triggering command:/usr/bin/dotnet dotnet build --no-restore (dns block)
  • vwvvsblobprodcus334.vsblob.vsassets.io
    • Triggering command:/usr/bin/dotnet dotnet restore (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>After reducing the form width, clicking the ToolStrip options triggers a Win32Exception error</issue_title>
<issue_description>### .NET version

.NET SDK 10.0.00-rtm.25523.111

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

No, it still repro on .NET 8.0 and .NET 9.0

Issue description

When the form width is reduced to prevent Toolstrip items from displaying, clicking the ToolBar Options throws aSystem.ComponentModel.Win32Exception (0x80004005): Failed to set Win32 parent window of the Control error.

.NET project
Image

.NET framework project
Image

Call Stack

See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.************** Exception Text **************System.ComponentModel.Win32Exception (0x80004005): Failed to set Win32 parent window of the Control.   at System.Windows.Forms.Control.SetParentHandle(HWND value)   at System.Windows.Forms.Control.CreateControl(Boolean ignoreVisible)   at System.Windows.Forms.Control.CreateControl()   at System.Windows.Forms.Control.WmShowWindow(Message& m)   at System.Windows.Forms.Control.WndProc(Message& m)   at System.Windows.Forms.ToolStrip.WndProc(Message& m)   at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, UInt32 msg, WPARAM wparam, LPARAM lparam)

Steps to reproduce

  1. Create a WinForms .NET project
  2. Add a ToolStrip to form designer
  3. Add toolStripComboBox and toolStripProgressBar to ToolStrip control
  4. Ctrl + F5 to run this project
  5. Narrow down the width of form to make sure no toolstrip Item display on form designer
  6. Click on the ToolBar Options</issue_description>

Comments on the Issue (you are@copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn moreCopilot coding agent tips in the docs.

Microsoft Reviewers:Open in CodeFlow

CopilotAIand others added2 commitsDecember 4, 2025 01:59
… widthWhen a ToolStripControlHost item (like ToolStripComboBox or ToolStripProgressBar) movesto the overflow dropdown, the hosted control should remain parented to the Owner ToolStrip,not the dropdown. ToolStripDropDown is a TopLevel popup window, and parenting controls toit can cause Win32Exception due to SetParent failures (e.g., DPI awareness mismatches).Fixes#14077Co-authored-by: SimonZhao888 <133954995+SimonZhao888@users.noreply.github.com>
Clarify why parenting controls to ToolStripDropDown causes Win32Exception(DPI awareness mismatches or window hierarchy constraints)Co-authored-by: SimonZhao888 <133954995+SimonZhao888@users.noreply.github.com>
CopilotAI changed the title[WIP] Fix Win32Exception on ToolStrip options click after form width reductionFix Win32Exception when clicking ToolBar Options after narrowing form widthDec 4, 2025
@dotnet-policy-servicedotnet-policy-servicebot added the draftdraft PR labelDec 4, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@SimonZhao888SimonZhao888Awaiting requested review from SimonZhao888

At least 1 approving review is required to merge this pull request.

Labels

draftdraft PR

Projects

None yet

Milestone

No milestone

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

@SimonZhao888

[8]ページ先頭

©2009-2025 Movatter.jp