Generate textboxes with:
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);
}
}
Manual formed textbox that only accepts numbers:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
const char Delete = (char)8;
e.Handled = !Char.IsDigit(e.KeyChar) && e.KeyChar != Delete;
}
My questions: 1. How do i set to generate texboxes that accepts only numbers?
2. i would like to have only two numbers (from 0 – 99 string pattern = @"^[0-9]{2}?$";). Or is any different way to do this.
is the textBox1_KeyPress the method to handle the validation of the Texbox input?
if so – just before adding the TextBox, add an event refference:
UPD:
another option (this is the dirty way):
before the this.Controls.Add(tb);