Home > DeveloperSection > Forums > C# How do disable a key
Tanuj Kumar

Total Post:134

Posted on    January-28-2014 12:10 AM

 C# C# 

 1 Reply(s)
 769  View(s)
Rate this:

How do I prevent the caret going to the next line in a text box when the 'ENTER' key has been pressed? In other words how to disable the 'ENTER' or 'RETURN' key in a text-box?

Pravesh Singh

Total Post:411

Posted on    January-28-2014 12:54 AM

Hi Tanuj,

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;


Don't want to miss updates? Please click the below button!

Follow MindStick