Answers for "c# textbox numbers only"

C#
5

c# textboxaccept only numbers

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
    }
Posted by: Guest on March-29-2021
0

c# textbox numbers only

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
        (e.KeyChar != '.'))
    {
            e.Handled = true;
    }

    // only allow one decimal point
    if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
    {
        e.Handled = true;
    }
}
Posted by: Guest on May-04-2021

Code answers related to "c# textbox numbers only"

C# Answers by Framework

Browse Popular Code Answers by Language