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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top