Fix ToolStripMenuItem character input in design mode
Fixes #13234
Proposed changes
- Add
IsInDesignModecheck before callingSetActiveToolStrip(this)inWM_SETFOCUShandler - Prevents modal menu mode from intercepting keyboard input in design surfaces
PR #13034 fixed #12916 by calling SetActiveToolStrip(this) on WM_SETFOCUS, but this unconditionally enters modal menu mode which redirects keyboard input to the ToolStrip. In design mode (e.g., DemoConsole), this prevents text entry when editing menu items.
if (!IsInDesignMode)
{
ToolStripManager.ModalMenuFilter.SetActiveToolStrip(this);
}
This follows the existing pattern at line 4614: if (!IsDropDown && !IsInDesignMode).
Customer Impact
- Users of custom design surfaces (like DemoConsole) can now enter text when adding ToolStripMenuItems
- No impact to Visual Studio designer (confirmed not to reproduce there)
Regression?
- Yes, introduced by #13034
Risk
- Low: minimal change, follows existing pattern, only affects design mode behavior
Test methodology
- Code review verified pattern consistency with existing
IsInDesignModechecks in same method - Issue confirmed to not reproduce in VS designer per comment from @ricardobossan
[!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:
st8vsblobprodcus339.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.25571.109.txt(dns block)- Triggering command:
/home/REDACTED/work/winforms/winforms/.dotnet/dotnet dotnet build --no-restore(dns block)If you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to the custom allowlist in this repository's Copilot coding agent settings (admins only)
Original prompt
This section details on the original issue you should resolve
<issue_title>Cannot enter characters when adding ToolStripMenuItem1 and then adding ToolStripMenuItem2 after pressing enter in DemoConsole application</issue_title> <issue_description>### .NET version
main branch of WinForms repo
Did it work in .NET Framework?
Yes
Did it work in any of the earlier releases of .NET Core or .NET 5+?
Yes, this is a regression issue. Not repro on .NET 9.0 from Release/9.0 branch of WinForms repo.
https://github.com/user-attachments/assets/11a56acc-3a27-43d0-adeb-20824cb2bb96
Issue description
Actual result: Cannot enter characters when adding ToolStripMenuItem1 and then adding ToolStripMenuItem2 after pressing enter in DemoConsole application.
https://github.com/user-attachments/assets/1e6fe900-449b-43bd-bfd1-e0c714f73a84
Expected result: Characters can be entered when adding ToolStripMenuItem1 and then adding ToolStripMenuItem2 after pressing enter in DemoConsole application.
https://github.com/user-attachments/assets/42c4d5a2-b530-4d27-a466-7db5e687c202
Steps to reproduce
Test sample: DemoConsole bases on main branch in Winforms repo.
More info:
- This issue rerpo in ContextMenuStrip/MenuStrip/ToolStrip/BindingNavigator control in DemoConsole application. </issue_description>
Comments on the Issue (you are @copilot in this section)
Still need to find a solution that resolves both this regression and the original problem from dotnet/winforms#12916 without reintroducing either.
git bisect log
git bisect start status: waiting for both good and bad commits good: [78c7bb89560a456a0f56aa05dc8b5ba222edf83f] System.Data.SqlClient - use version recommended by the SQL team, I couldn't find v5, not sure if it exists, we are not referencing this package right ow, so this is not a problem. Nuget.Packaging - use version that does not pull in vulnerable System.Formats.Asn1 (v8.0,0) Change in the VB test project - this assembly is not references directly, transitive versions can be resolved from the central packaging git bisect good 78c7bb89560a456a0f56aa05dc8b5ba222edf83f status: waiting for bad commit, 1 good commit known bad: [9092b067aaec1122e8aa0163951cbe5862431125] [main] Update dependencies from dotnet/runtime (#13363) git bisect bad 9092b067aaec1122e8aa0163951cbe5862431125 bad: [1a430821e2c4696a5bd8f79db746aeb3ffb1f608] Ensure that System.Drawing facade assembly is built before the tests that consume it are. (#13119) git bisect bad 1a430821e2c4696a5bd8f79db746aeb3ffb1f608 bad: [1a430821e2c4696a5bd8f79db746aeb3ffb1f608] Ensure that System.Drawing facade assembly is built before the tests that consume it are. (#13119) git bisect bad 1a430821e2c4696a5bd8f79db746aeb3ffb1f608 good: [707898d6ce7eea814da61e2ec05bde666d27b85b] [main] Update dependencies from dotnet/arcade (#13032) git bisect good 707898d6ce7eea814da61e2ec05bde666d27b85b bad: [316a77b46ba75f2a68aef1abcf4addb47e75bc79] Remove extra dot at the end of resource string (#13091) git bisect bad 316a77b46ba75f2a68aef1abcf4addb47e75bc79 bad: [5e8147d352c945eea0c9135faf0996d96993f8b9] Resizes
DemoConsoleproject'sMainFormfor convenience and to make everything visible in the surface designer (#13050) git bisect bad 5e8147d352c945eea0c9135faf0996d96993f8b9 bad: [6e112b86c1b98a44f4473d45a7a7ec0d90354a7c] fix dotnet/winforms#12916 Cannot use down to expand ToolStripDropDownButton in toolStrip2 after using right/Left to collapse ToolStripDropDownButton in toolStrip1 (#13034) git bisect bad 6e112b86c1b98a44f4473d45a7a7ec0d90354a7c good: [e9f1c43f83a393d0c7d3e0af70c26f589c5570f9] Enable nullability in DesignerActionMethodItem (#12676) git bisect good e9f1c43f83a393d0c7d3e0af70c26f589c5570f9 good: [e65c611ef4456c8a0d8250a10afcc27466f7cd23] [main] Update dependencies from dotnet/arcade (#13038) git bisect good e65c611ef4456c8a0d8250a10afcc27466f7cd23 good: [2dc1fbe6e65e068347aeb62ea558637ad35e647f] Add code coverage for ControlCodeDomSerializer (#13011) git bisect good 2dc1fbe6e65e068347aeb62ea558637ad35e647f first bad commit: [6e112b86c1b98a44f4473d45a7a7ec0d90354a7c] fix dotnet/winforms#12916 Cannot use down to expand ToolStripDropDownButton in toolStrip2 after using right/Left to collapse ToolStripDropDownButton in toolStrip1 (#13034)
- Fixes dotnet/winforms#13400
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Microsoft Reviewers: Open in CodeFlow
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 77.15474%. Comparing base (09c759b) to head (4714510).
:warning: Report is 1 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #14078 +/- ##
===================================================
- Coverage 77.16719% 77.15474% -0.01246%
===================================================
Files 3279 3279
Lines 645317 645320 +3
Branches 47718 47719 +1
===================================================
- Hits 497973 497895 -78
- Misses 143657 143729 +72
- Partials 3687 3696 +9
| Flag | Coverage Δ | |
|---|---|---|
| Debug | 77.15474% <100.00000%> (-0.01246%) |
:arrow_down: |
| integration | 18.98213% <100.00000%> (-0.03711%) |
:arrow_down: |
| production | 52.01845% <100.00000%> (-0.02764%) |
:arrow_down: |
| test | 97.40749% <ø> (ø) |
|
| unit | 49.47212% <100.00000%> (-0.00053%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.