Hi,
you must first create the control programmatically.
Example:
var txt = new TextBox();
txt.name = "myNewTextBox";
Then you can add it to your flowLayoutPanel:
flowLayoutPanel1.Controls.Add(txt);
Note: you cannot then refer to that TextBox in your code with this.myNewTextBox
. You need to either save a reference to it (global variable or global dictionary?) or get its reference from flowLayoutPanel1.Controls. You may also need to handle the names of the textboxes: if you add two textboxes to your flowLayoutPanel with the same name, WinForm will assign the last added one a different name ("myNewTextBox1" ?).
Example:
flowLayoutPanel1.Controls["myNewTextBox"].Text = "Hi!";
Handle Elements added to FlowLayoutPanel
As previously stated, you need to manage the name of textboxes (for instance, by using a counter) and then retrieve the TextBoxes in code knowing either the name or their index in the
FlowLayoutPanel.Controls
array.
Examples:
var txt3 = myFlowLayoutPanel.Controls[2];
var txtSpecial = myFlowLayoutPanel.Controls["mySpecialTextBox"]
Side note: when in doubt, consult MSDN. In this particular case go here.
Hope this helps.
LG