---
title: "How to create Numeric Text Box in C sharp"  
description: "/* Style Definitions */   table.MsoNormalTable  	{mso-style-name:\"Table Normal\";  	mso-tstyle-rowband-size:0;  	mso-tstyle-colband-size:0;  	mso-st"  
author: "Uttam Misra"  
published: 2010-07-31  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/70/how-to-create-numeric-text-box-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# How to create Numeric Text Box in C sharp

Numeric text box means, a Text Box which can only accepts numeric values.\

![How to create Numeric Text Box in C sharp](https://www.mindstick.com/mindstickarticle/6e3c047c-17aa-4ea2-b390-a8b756404f09/images/84135cda-b4b4-41e0-9ccd-3fa621ecb722.png)

##### Code to implement a numeric text box.

Code should be written on textbox keypress event.

```
  private void textBox1_KeyPress(object sender, KeyPressEventArgs e)        {            if (char.IsDigit(e.KeyChar) == false && e.KeyChar != '.' && e.KeyChar!='\b')//checking whether pressed key is number, decimal or backspace.//If false then we will set Handled variable of KeyPressEventArgs to true.//By doing this system will get a message that character of keypressed//is executed and hence aplpa numeric character will not be displayed//except decimal.                 e.Handled=true;            else if (e.KeyChar == '.')                if (textBox1.Text.Contains('.'))                    e.Handled=true;            //checking whether decimal key is pressed or not, if true then checking//whether decimal is already present or not, as we can have only//one decimal point in a text box.        }
```

---

Original Source: https://www.mindstick.com/articles/70/how-to-create-numeric-text-box-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
