Jan*_*jti 3 .net c# textbox winforms
使用以下内容生成文本框:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
手动形成的文本框只接受数字:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
const char Delete = (char)8;
e.Handled = !Char.IsDigit(e.KeyChar) && e.KeyChar != Delete;
}
Run Code Online (Sandbox Code Playgroud)
我的问题:1.如何设置生成只接受数字的texbox?
2.我想只有两个数字(0 - 99 string pattern = @"^[0-9]{2}?$";).或者是以任何不同的方式来做到这一点.