Dynamically create an array of text fields and winforms shortcuts

I need to create an array of shortcuts and text fields dynamically.

I have a groupBox and I need to add to it above. What is the best way to align correctly? How do you get a seat?

below does not work

public void TestCreateInputLabelAndTextBox() { foreach (Parameter parameter in Params) { var lbl = new Label(); lbl.Name = "lbl" + parameter.Name; lbl.Text = parameter.Name; lbl.AutoSize = true; lbl.Location = new Point(7, 30); lbl.Name = "label1"; lbl.Size = new Size(35, 13); var txtBox = new TextBox(); txtBox.Name = "txt" + parameter.Name; txtBox.Text = parameter.Name; txtBox.Location = new Point(20, 20); txtBox.Location = new Point(49, 22); txtBox.Size = new Size(100, 20); groupBox1.Controls.Add(lbl); groupBox1.Controls.Add(txtBox); } } 

How do you do this?

0
source share
2 answers

you must create an array of text fields and folders for example:

 TextBox[] txt= new TextBox[10]; for (int i = 0; i <=10; i++) { txt(i) = new TextBox(); txt(i).Text = i.Tostring(); if (i > 0) { txt(i).Left = txt(i - 1).Right; } this.Controls.Add(txt(i)); } 
+1
source

In addition to the comments above, I used tablePanelLayout.

I wish my question seemed to be clear. I tried to be as concise as possible, because I believe that the more you talk, the more you can confuse someone who can help you.

All I needed was some pointers. Using tablePanellayout, I solved the problem. thanks for your comments

0
source

All Articles