// override this to route command shortcuts to command service
            protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
            {
                bool consumed = false;

                // Route to command service if not a text input control. If it is a text input control,
                //  only route to the command service if the keypress is not standard textbox input.
                Control focusedControl = User32.GetFocusedControl();

                if (
                    (!(focusedControl is TextBoxBase) && !(focusedControl is ComboBox)) ||
                    !KeysUtil.IsTextBoxInput(focusedControl, keyData)
                    )
                {
                    ICommandService commandService = m_controlHostService.m_commandService;
                    if (commandService != null)
                    {
                        consumed = commandService.ProcessKey(keyData);
                    }
                }

                // If the command key wasn't processed, then let the base handle it so that certain
                //  default behavior like the access keys (the underlines that appear when Alt is held down)
                //  still work correctly.
                if (!consumed)
                {
                    consumed = base.ProcessCmdKey(ref msg, keyData);
                }

                return(consumed);
            }
示例#2
0
            /// <summary>
            /// Process command key</summary>
            /// <param name="msg">Windows message</param>
            /// <param name="keyData">Key</param>
            /// <returns>True iff key processed</returns>
            /// <remarks>Calling the base ProcessCmdKey allows this keypress to be consumed by owning
            /// Controls like PropertyView and PropertyGridView and ControlHostService.
            /// Returning false allows the keypress to escape to IsInputKey and to any built-in
            /// text editing functionality, like Ctrl+A (copy text), Ctrl+V, Ctrl+X, Delete, etc.
            /// Returning true means that this keypress has been consumed by this method and this
            /// event is not passed on to any other methods or Controls.</remarks>
            protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
            {
                switch (keyData)
                {
                // If we don't handle Enter here, the DOM is not modified until focus is lost.
                // We return 'false' to allow the built-in functionality of selecting all the
                //  text, which is an important visual cue that the Enter key did something.
                case Keys.Enter:
                    SetProperty();
                    return(false);

                // If we don't handle Ctrl+A here, the ComboBox does something weird, perhaps
                //  inserting an unprintable character or newline or something that clears
                //  the editable text in the ComboBox. We return 'true' to avoid the bad
                //  built-in behavior.
                case (Keys.Control | Keys.A):
                    SelectAll();
                    return(true);
                }

                // For some reason, the ATF WinFormsUtil.GetFocusedControl() returns null and so the check
                //  for standard text input doesn't get performed by ControlHostService. So we need
                //  to do it. http://sf.ship.scea.com/sf/go/artf34968
                if (KeysUtil.IsTextBoxInput(this, keyData))
                {
                    return(false);
                }

                return(base.ProcessCmdKey(ref msg, keyData));
            }