Skip to content

Commit

Permalink
Fix ToolStripDropDown.ProcessDialogKey method to handle (do nothing) …
Browse files Browse the repository at this point in the history
…Up and Down keys when item has no sub-items
  • Loading branch information
v-elnovikova committed Feb 8, 2023
1 parent 63164a7 commit 1ca0df4
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,12 @@ protected internal override bool ProcessDialogKey(Keys keyData)
{
Keys keyCode = (Keys)keyData & Keys.KeyCode;

// Items on the overflow should have the same kind of keyboard handling as a toplevel
bool isTopLevel = (!IsOnDropDown || IsOnOverflow);

if (HasDropDownItems)
{
// Items on the overflow should have the same kind of keyboard handling as a toplevel
bool isToplevel = (!IsOnDropDown || IsOnOverflow);

if (isToplevel && (keyCode == Keys.Down || keyCode == Keys.Up || keyCode == Keys.Enter || (SupportsSpaceKey && keyCode == Keys.Space)))
if (isTopLevel && (keyCode == Keys.Down || keyCode == Keys.Up || keyCode == Keys.Enter || (SupportsSpaceKey && keyCode == Keys.Space)))
{
ToolStrip.s_selectionDebug.TraceVerbose("[SelectDBG ProcessDialogKey] open submenu from toplevel item");

Expand All @@ -561,7 +561,7 @@ protected internal override bool ProcessDialogKey(Keys keyData)

return true;
}
else if (!isToplevel)
else if (!isTopLevel)
{
// if we're on a DropDown - then cascade out.
bool menusCascadeRight = (((int)DropDownDirection & 0x0001) == 0);
Expand All @@ -583,6 +583,14 @@ protected internal override bool ProcessDialogKey(Keys keyData)
}
}
}
else
{
// For a top-level item without sub-items: do nothing on Up/Down
if (isTopLevel && (keyCode == Keys.Down || keyCode == Keys.Up))
{
return true;
}
}

if (IsOnDropDown)
{
Expand Down

0 comments on commit 1ca0df4

Please sign in to comment.