//Write code on Textbox KeyPress Event.
=============================
private void txtQty_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '0' || e.KeyChar == '1' || e.KeyChar == '2' || e.KeyChar == '3' || e.KeyChar == '4' || e.KeyChar == '5' || e.KeyChar == '6' || e.KeyChar == '7' || e.KeyChar == '9' || e.KeyChar == '8' || e.KeyChar == '.')
{
if (txtQty.Text.ToString().Contains(".") || e.KeyChar == '.')
{
if (txtQty.Text.ToString().Contains(".") && e.KeyChar == '.')
{
e.Handled = true;
}
else
{
e.Handled = false;
}
}
}
else if (e.KeyChar == '\b')
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}