Beispiel #1
0
        private void toolStripTextSearch_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Down && e.KeyCode != Keys.Up && e.KeyCode != Keys.Enter)
            {
                return;
            }
            ToolStrip     parent    = toolStripTextSearch.GetCurrentParent();
            ToolStripItem prev_item = null;
            ToolStripItem next_item = null;
            bool          at_item   = false;

            foreach (ToolStripItem itm in parent.Items)
            {
                if (itm == toolStripTextSearch)
                {
                    at_item = true;
                }

                if (itm as ToolStripMenuItem == null)
                {
                    continue;
                }

                if (!itm.Visible)
                {
                    continue;
                }

                if (!at_item && itm != toolStripTextSearch)
                {
                    prev_item = itm;
                }

                if (at_item)
                {
                    next_item = itm;
                    break;
                }
            }
            if (e.KeyCode == Keys.Enter && next_item != null)
            {
                miItem_OpenURL(next_item, null);
            }

            if (e.KeyCode == Keys.Down && next_item != null)
            {
                e.SuppressKeyPress = true;
                e.Handled          = true;
                parent.Focus();
                next_item.Select();
            }
            if (e.KeyCode == Keys.Up && prev_item != null)
            {
                e.SuppressKeyPress = true;
                e.Handled          = true;
                parent.Focus();
                prev_item.Select();
            }
        }