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


Thanks
A Rahim Khan

About these ads
    • irfan
    • March 28th, 2012

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

  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 74 other followers

%d bloggers like this: