728x90 AdSpace

  • Latest News

    [Tips] C# TextBox only accept number not character

    You can use below function. This function can help you just allow input number not characters.












    C# TextBox only accept number not character



    // Developer: VịLH / Zidane (huuvi168@gmail.com)
    // Last Modified: 2016-07-01

    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;
    }



    Any feedback or question, leave your comment, we can disccuss about it!
    Zidane
    http://learn-tech-tips.blogspot.com/
    • Blogger Comments
    • Facebook Comments

    0 comments:

    Post a Comment

    Item Reviewed: [Tips] C# TextBox only accept number not character Rating: 5 Reviewed By: Unknown
    Scroll to Top