C# How do disable a key

Total Post:134

Points:940

C# 
C#
 1453  View(s)
Ratings:
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?

  1. Re: C# How do disable a key

    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;
    }

      Modified On Apr-04-2018 02:07:53 AM

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.