【发布时间】:2012-02-19 11:31:43
【问题描述】:
生成文本框:
public void addTextBox(int number)
{
for (int i = 0; i < number; i++)
{
string name = "tb_" + (i + 1).ToString("00");
tb = new TextBox();
tb.Name = name;
tb.Location = new Point(x, y);
tb.Width = 20;
x += 30;
this.Controls.Add(tb);
}
}
仅接受数字的手动格式文本框:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
const char Delete = (char)8;
e.Handled = !Char.IsDigit(e.KeyChar) && e.KeyChar != Delete;
}
我的问题:1.如何设置生成只接受数字的texbox?
2. 我只想要两个数字(从 0 到 99 string pattern = @"^[0-9]{2}?$";)。或者有什么不同的方法来做到这一点。
【问题讨论】: