none
Detecting ESC key stroke in ToolStripTextBox RRS feed

  • Question

  • Hi,

    Trying to detect ESC key pressed while the user is entering text into ToolStripTextBox.  Pressing the key does not raise KeyDown, KeyUp, or KeyPress event.  Rather, it simply moves down focus off the control.    This probably applies to regular TextBox as well, though I have not tested it.

    Is there a way to detect ESC key being entered into the text box?

    Thanks in advance.

    Friday, September 8, 2006 2:10 AM

Answers

  • Escape is a special key.

    To override it....try this:

     

    protected override bool ProcessCmdKey(ref Message, Keys keyData)

    {

       if (keyData == Keys.Escape)

       {

          //Escape key press, handle it your way but be sure to return true

          return true;

       }

       else

       {

          return false;

       }

    }

     

    hope this helps

    Friday, September 8, 2006 2:48 AM
    Moderator

All replies

  • Escape is a special key.

    To override it....try this:

     

    protected override bool ProcessCmdKey(ref Message, Keys keyData)

    {

       if (keyData == Keys.Escape)

       {

          //Escape key press, handle it your way but be sure to return true

          return true;

       }

       else

       {

          return false;

       }

    }

     

    hope this helps

    Friday, September 8, 2006 2:48 AM
    Moderator
  • Thanks - it nailed my question.

    The documentation on the method is almost nil.  I assume it should return true if it handled the message, and false otherwise to allow handler chaining?

    Also, I see a method of same signature to TextBox.  Looks like it should  do the same as the method for ToolStripTextBox, but the documentation reads:

    "Gets a value indicating the state of the ShortcutsEnabled property."

    ??

    Thanks again.

     

    Friday, September 8, 2006 5:36 AM