How to override a TextBox's KeyPress event

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jason Huang

    How to override a TextBox's KeyPress event

    Hi,

    How do I override a TextBox's KeyPress evnt? And how do we use it?
    Thanks for help.


    Jason


  • =?Utf-8?B?SWJyYWhpbSBTaGFtZWVxdWU=?=

    #2
    RE: How to override a TextBox's KeyPress event

    Hi
    Set the KeyPressEventAr gs.Handled to True to cancel the event.
    --
    ---------------------------
    Thanks,
    Ibrahim

    Software Consultant - Web Development, GB


    "Jason Huang" wrote:
    Hi,
    >
    How do I override a TextBox's KeyPress evnt? And how do we use it?
    Thanks for help.
    >
    >
    Jason
    >
    >
    >

    Comment

    • michel.desangles@gmail.com

      #3
      Re: How to override a TextBox's KeyPress event

      On 7 août, 11:04, "Jason Huang" <JasonHuang8... @hotmail.comwro te:
      Hi,
      >
      How do I override a TextBox's KeyPress evnt?   And how do we use it?
      Thanks for help.
      >
      Jason
      I think your question is related to the one you asked a few days ago,
      about handling Return in a textbox ?

      In the designer, select your textbox (say it's called textBox1),
      choose the properties by typing F4, select the events pane by clicking
      on the, er, thunder strike icon at the top of the property sheet,
      place your cursor inside the "KeyPress" event and type Return. It will
      create this method in your code :

      private void textBox1_KeyPre ss(object sender, KeyPressEventAr gs e)
      {
      }

      Edit it so :

      private void textBox1_KeyPre ss(object sender, KeyPressEventAr gs e)
      {
      if (e.KeyChar == 13)
      {
      e.Handled = true;
      // Do something : validate your input,
      // close your form, whatever
      }
      }

      Just replace the comments with whatever you want to do when the return
      key is pressed inside the textbox.

      Michel

      Comment

      Working...