Number Only TextBox C# Windows Application

Put this code snippet your TextBox KeyPress Event, you will have your Number Only TextBox Working.

private void numberOnlyTextBox1_KeyPress(object sender, KeyPressEventArgs e)
 //allow digits only
 if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
   e.Handled = true;

 // allow one decimal point
 if (e.KeyChar == '.' && (sender as TextBox).Text.IndexOf('.') > -1)
  e.Handled = true;

A Rahim Khan

    • irfan
    • March 28th, 2012

    Realy nice,
    Is there any way to make master page in c# window application.I need it urgently.

  1. You can use Regular Expression too..

    System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text, “[ ^ 0-9]”)

    Source….Numeric Only Textbox


  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: