Tuesday, January 29, 2013

Enter only Numeric Data in TextBox


private void TxtQuantity_KeyPress(object sender, KeyPressEventArgs e)
        {
if (char.IsDigit(e.KeyChar) == false && char.IsLetter(e.KeyChar) == false && char.IsControl(e.KeyChar) == false && e.KeyChar != '.' && e.KeyChar != ' ')
            {
                e.Handled = true;
                MessageBox.Show("You can enter only number.", "KenCloud", MessageBoxButtons.OK, MessageBoxIcon.Information);
                TxtQuantity.Clear();
                TxtQuantity.Focus();
                return;
            }
}

No comments:

Post a Comment