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

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

}

posted @ 2013-06-18 00:14  有创软件工作室  阅读(2347)  评论(0编辑  收藏  举报