I am developing a Windows Form application. One requirement I have is to create new text boxes on a click of button inside a Tab Page. This is what I have done inside the button (btnAdd) click event:
TextBox textBox1 = new TextBox();
textBox1.Name = DateTime.Now.ToString() + "textbox";
textBox1.Text = DateTime.Now.ToString() + "textbox";
textBox1.Size = new Size(200, 30);
textBox1.Location = new Point(tbpEx.Left + 20, loc);
tbpEx.Controls.Add(textBox1);
loc = textBox1.Height + 20 ;
So that I can get the text boxes one below the other. But I click the button, the text boxes get added, but after 2 text boxes there are no more text boxes visible.
I have tried to place another button(btnCnt) on the form that counts the controls in the tbpEX (I have no other controls in this tab page (in fact it is the only control - that too a tab page - on the form). In this button click I have this code:
foreach (Control c in tbpEx.Controls)
{
lblMsg.Text = lblMsg.Text + c.Name + ":" + c.Parent.Name + Environment.NewLine;
}
I have clicked the btnAdd 7 times but I can see only 2 text boxes. However, when I click the btnCnt, lblMsg displays 7 textboxes.
Why I am unable to see the erest of the text boxes?