Allow only integers in TextBoxes

后端 未结 6 1366
情书的邮戳
情书的邮戳 2021-01-22 12:45

I\'m having a problem with checking textboxes and making sure there\'s only integers in them.

So far I\'m able to confirm that there\'s text in the textboxes, but checki

6条回答
  •  借酒劲吻你
    2021-01-22 13:16

    You can use the int.TryParse method to check if the string is an integer:

    int n = 0;
    bool isNumber = int.TryParse(textBox1.Text, out n);
    
    if (!isNumber)
       return;
    

提交回复
热议问题