在C# 中 如何限制在文本框(textBox)中输入的类型为正整数

在文本框的 KeyPress 事件中写下这些代码就可以保证是正整数了
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsNumber(e.KeyChar) || e.KeyChar == ''))
{
e.Handled = true;
}

}

原文地址:https://www.cnblogs.com/xiaxiaoping/p/3141483.html