Robertspark wrote:Thanks Dan
Yes there is a bit that you did not know as I was already limiting the technical characters to 2 via the max length property, and the numbers were purely integers (decimal point excluded from the char)
The bit that I am not getting is the "and just check for 11", as that is the bit I cannot seem to get.
What I should of said is check for 10,11,12 and would of eliminated any confusion. if you don't care or want backspace to work remove !char.IsControl(e.KeyChar)
- Code: Select all
private void textbox_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
if (textbox.TextLength == 1 && e.KeyChar != '0' & e.KeyChar != '1'& e.KeyChar != '2' & !char.IsControl(e.KeyChar))
{
e.Handled = true;
}
}