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 9, 2023
1 parent 63164a7 commit b4ffd32
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -542,26 +542,26 @@ 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");

if (Enabled || DesignMode)
{
// |__[ * File ]_____| * is where you are. Up or down arrow hit should expand menu
// |__[ * File ]_____| * is where you are. Up or down arrow hit should expand menu.
ShowDropDown();
KeyboardToolTipStateMachine.Instance.NotifyAboutLostFocus(this);
DropDown.SelectNextToolStripItem(null, true);
}// else eat the key

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 b4ffd32

Please sign in to comment.