none
how to disable key press RRS feed

  • Question

  • Hi,

    I have a  windows form in VS2003.

    I want to prevent user from pressing any key on the text box.

    I have tried for Key_Down event. But there is no property like e.SuppressKeyPress in VS2003.

    Can you suggest some other approach.

    I cannot make the textbox readonly or enabled=false. As it greys out the textbox.

    Thanks in advance.

     

     

    Wednesday, November 18, 2009 11:24 AM

Answers

  • Hi,

    Try setting e.Handled to true at the keypress event of textbox.

    Here is a sample.

            private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                e.Handled = true;
            }
    • Proposed as answer by A.m.a.L Hashim Wednesday, November 18, 2009 11:57 AM
    • Marked as answer by a.Net fan Wednesday, November 18, 2009 12:07 PM
    Wednesday, November 18, 2009 11:43 AM

All replies

  • Hi,

    Try setting e.Handled to true at the keypress event of textbox.

    Here is a sample.

            private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                e.Handled = true;
            }
    • Proposed as answer by A.m.a.L Hashim Wednesday, November 18, 2009 11:57 AM
    • Marked as answer by a.Net fan Wednesday, November 18, 2009 12:07 PM
    Wednesday, November 18, 2009 11:43 AM
  • It worked.. :-)

    Thanks for the help...
    Wednesday, November 18, 2009 12:07 PM