KeyDown() public method

Perform key down handling.
public KeyDown ( KeyEventArgs e ) : void
e System.Windows.Forms.KeyEventArgs A KeyEventArgs that contains the event data.
return void
コード例 #1
0
        /// <summary>
        /// Key has been pressed down.
        /// </summary>
        /// <param name="c">Reference to the source control instance.</param>
        /// <param name="e">A KeyEventArgs that contains the event data.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public virtual void KeyDown(Control c, KeyEventArgs e)
        {
            Debug.Assert(c != null);
            Debug.Assert(e != null);

            // Validate incoming references
            if (c == null)
            {
                throw new ArgumentNullException(nameof(c));
            }

            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            switch (e.KeyCode)
            {
            case Keys.Enter:
            case Keys.Space:
                // Only interested in enabled items
                if (_menuLinkLabel.ItemEnabled)
                {
                    PressMenuLinkLabel(true);
                }

                break;

            case Keys.Tab:
                ViewManager.KeyTab(e.Shift);
                break;

            case Keys.Home:
                ViewManager.KeyHome();
                break;

            case Keys.End:
                ViewManager.KeyEnd();
                break;

            case Keys.Up:
                ViewManager.KeyUp();
                break;

            case Keys.Down:
                ViewManager.KeyDown();
                break;

            case Keys.Left:
                ViewManager.KeyLeft(true);
                break;

            case Keys.Right:
                ViewManager.KeyRight();
                break;
            }
        }
コード例 #2
0
        /// <summary>
        /// Raises the KeyDown event.
        /// </summary>
        /// <param name="e">A KeyEventArgs that contains the event data.</param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            // Cannot process a message for a disposed control
            if (!IsDisposed)
            {
                // Do we have a manager for processing key messages?
                ViewManager?.KeyDown(e);
            }

            // Let base class fire events
            base.OnKeyDown(e);
        }
コード例 #3
0
        /// <summary>
        /// Raises the KeyDown event.
        /// </summary>
        /// <param name="e">A KeyEventArgs that contains the event data.</param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            // Cannot process a message for a disposed control
            if (!IsDisposed)
            {
                // If the user pressed the escape key
                if (e.KeyData == Keys.Escape)
                {
                    // Kill ourself
                    Dispose();
                }
                else
                {
                    // Do we have a manager for processing key messages?
                    ViewManager?.KeyDown(e);
                }
            }

            // Let base class fire events
            base.OnKeyDown(e);
        }
コード例 #4
0
        /// <summary>
        /// Key has been pressed down.
        /// </summary>
        /// <param name="c">Reference to the source control instance.</param>
        /// <param name="e">A KeyEventArgs that contains the event data.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public virtual void KeyDown(Control c, KeyEventArgs e)
        {
            Debug.Assert(c != null);
            Debug.Assert(e != null);

            // Validate incoming references
            if (c == null)
            {
                throw new ArgumentNullException(nameof(c));
            }

            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            switch (e.KeyCode)
            {
            case Keys.Enter:
            case Keys.Space:
                // Only interested in enabled items
                if (_menuItem.ItemEnabled)
                {
                    // Do we press the item or show the sub menu?
                    if (!_menuItem.HasSubMenu)
                    {
                        PressMenuItem();
                    }
                    else
                    {
                        _menuItem.ShowSubMenu(true);
                    }
                }
                break;

            case Keys.Tab:
                ViewManager.KeyTab(e.Shift);
                break;

            case Keys.Home:
                ViewManager.KeyHome();
                break;

            case Keys.End:
                ViewManager.KeyEnd();
                break;

            case Keys.Up:
                ViewManager.KeyUp();
                break;

            case Keys.Down:
                ViewManager.KeyDown();
                break;

            case Keys.Left:
                // We wrap if are the first context menu shown, rather than a sub menu showing
                if (ViewManager.KeyLeft(!_menuItem.HasParentMenu))
                {
                    // User tried to fall off the left edge, so dismiss ourself and let the
                    // keyboard access take us back to the owning context menu instance
                    _menuItem.DisposeContextMenu();
                }
                break;

            case Keys.Right:
                // If enabled and with a sub menu, then show the sub menu
                if (_menuItem.ItemEnabled && _menuItem.HasSubMenu)
                {
                    _menuItem.ShowSubMenu(true);
                }
                else
                {
                    ViewManager.KeyRight();
                }

                break;
            }
        }