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