How do I prevent the caret to go to the next line when the 'ENTER' key has being pressed on a text-box? In other words how to disable the 'ENTER' or 'RETURN' key on a text-box?
+5
A:
You can write the OnKeyDown event. you can use the e.SuppressKeyPress to tell .net that you handle the key. something like this:
if (e.KeyCode == Keys.Enter) {
e.SuppressKeyPress = true;
}
Jedi Master Spooky
2009-03-13 18:41:07
+1 for useful information for the general case even if it's not the best approach for this particular scenario
Davy8
2009-03-13 18:46:15
WOW fast reply... this is way better than other forums (don't want to say which ones) where people insult people who ask questions.Thanks, thanks.
2009-03-13 20:27:50
KeyPressEventArgs doesn't contains SuppressKeyPress... I am using OnKeyPress event
2009-03-13 20:30:43
If you want to suppress de key you would have to use OnKeyDown
Jedi Master Spooky
2009-03-13 23:44:32
I am afraid not. But you can override OnKeyDown as Jedi Master Spooky suggests.
Jakob Christensen
2009-03-14 07:14:00