M Murugesh Bakthavachalam Feb 24, 2011 #2 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; } }
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; } }