hi friends this is the code for preventing the textbox to accept other than numbers
private void txtAccount_KeyPress(object sender, KeyPressEventArgs e)
{
TextBox txt = (TextBox)sender;
if (((int)e.KeyChar >= 48 && (int)e.KeyChar <= 57) || ((int)e.KeyChar == 8))
{
e.KeyChar = e.KeyChar;
}
else
{
e.KeyChar = Convert.ToChar(0);
}
if (txt.Text.Length - txt.SelectedText.Length >= 9 && ((int)e.KeyChar != 8))
{
e.KeyChar = Convert.ToChar(0);
}
}
No comments:
Post a Comment