【发布时间】:2014-04-08 08:09:02
【问题描述】:
我一直在研究here和dotnetperls的解决方案,试图找到一种方法来格式化我的文本框以仅允许数字字符。我要么只是不明白,要么真的不明白代码来做我想做的事。
我有一个表单,它会根据在另一个表单中按下的按钮而改变,我需要年龄框只允许最多 99 个数字字符(因此用户可以输入 1-99 范围内的年龄。我'已经研究过正则表达式方法和屏蔽文本框,但就是不明白。
有人能指出我将用来实现这一目标的方向吗?
我的代码如下:
private void AddItem_Load(object sender, EventArgs e)
{
if (formName == "customer")
{
this.Text = "Add Customer";
lblZero.Text = "ID:";
lblOne.Text = "Customer Name:";
lblTwo.Text = "Address Line 1:";
lblThree.Text = "Address Line 2:";
lblFour.Text = "Town:";
lblFive.Text = "Postcode:";
lblSix.Text = "Age:";
txtID.Text = Convert.ToString(customerList.NewID());
txtID.Enabled = false;
}
else
{
this.Text = "Add Product";
lblZero.Text = "Product ID:";
lblOne.Text = "Product Code:";
lblTwo.Text = "Product Name:";
lblThree.Text = "Product Description:";
lblFour.Text = "Price:";
lblFive.Text = " --------- ";
lblSix.Text = " ---------";
txtID.Text = Convert.ToString(productList.NewID());
txtID.Enabled = false;
txtFive.Enabled = false;
txtSix.Enabled = false;
}
}
表单上的文本框标记为 txtZero.txt ~ txtSix.txt。
非常感谢所有帮助:)
【问题讨论】: