---
title: "C# How do disable a key"  
description: "C# How do disable a key"  
author: "Anonymous User"  
published: 2014-01-28  
updated: 2014-01-28  
canonical: https://www.mindstick.com/forum/1893/c-sharp-how-do-disable-a-key  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# C# How do disable a key

How do I prevent the caret going to the next line in a [text](https://www.mindstick.com/blog/301635/did-people-reinvent-texting-to-express-the-full-range-of-emotions) box when the 'ENTER' key has been pressed? In other words how to [disable](https://www.mindstick.com/forum/12901/how-to-disable-enable-input-box-in-aspx-with-value-from-sql) the 'ENTER' or 'RETURN' key in a text-box?

## Replies

### Reply by Pravesh Singh

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;}
```


---

Original Source: https://www.mindstick.com/forum/1893/c-sharp-how-do-disable-a-key

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
