TextBox only numbers and decimal seperator

  • Thread starter Thread starter Joza
  • Start date Start date
try this..

bool bDecimal = false;
private void txtBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (Char.IsDigit(e.KeyChar) || e.KeyChar == 8 || e.KeyChar == '.')
{
if (e.KeyChar == '.')
{
if (bDecimal)
{
e.Handled = true;
}
else
{
e.Handled = false;
}
bDecimal = true;
}
else
{
e.Handled = false;
}

}
else
{
e.Handled = true;
}
}
 
Back
Top