Skip to content

Commit 4da479f

Browse files
committed
fix #13400 Cannot enter characters when adding ToolStripMenuItem1 and then adding ToolStripMenuItem2 after pressing enter in DemoConsole application
1 parent 71a8e95 commit 4da479f

File tree

1 file changed

+20
-1
lines changed
  • src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips

1 file changed

+20
-1
lines changed

src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStrip.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4579,7 +4579,11 @@ protected override void WndProc(ref Message m)
45794579
SnapFocus((HWND)(nint)m.WParamInternal);
45804580

45814581
// For fix https://github.com/dotnet/winforms/issues/12916
4582-
ToolStripManager.ModalMenuFilter.SetActiveToolStrip(this);
4582+
// Narrow down the range, because ToolStripDropDown is ToolStrip too. we only need to set outer ToolStrip active.
4583+
if (IsOuterToolStrip(this))
4584+
{
4585+
ToolStripManager.ModalMenuFilter.SetActiveToolStrip(this);
4586+
}
45834587
}
45844588

45854589
if (!AllowClickThrough && m.MsgInternal == PInvokeCore.WM_MOUSEACTIVATE)
@@ -4646,6 +4650,21 @@ protected override void WndProc(ref Message m)
46464650
// WM_DESTROY.
46474651
_dropDownOwnerWindow?.DestroyHandle();
46484652
}
4653+
4654+
static bool IsOuterToolStrip(ToolStrip toolStrip)
4655+
{
4656+
static ToolStrip getParentToolStrip(ToolStrip toolStrip)
4657+
{
4658+
if (toolStrip.Parent is ToolStrip parent)
4659+
{
4660+
return getParentToolStrip(parent);
4661+
}
4662+
4663+
return toolStrip;
4664+
}
4665+
4666+
return toolStrip == getParentToolStrip(toolStrip);
4667+
}
46494668
}
46504669

46514670
// Overridden to return Items instead of Controls.

0 commit comments

Comments
 (0)