for(int i=0;What to write;i++) { Button btnTest = new Button(); }
for(int i=0; i<5; i++) { Button btnTest = new Button(); btnText.Text = i.ToString(); btnTest.Location = new Point (i * 50, 50); Controls.Add(btnTest); }
for(int i=0;i<5;i++) { Button btnTest = new Button(); btnTest.Text = "whatever"; }
System.Windows.Forms.Button[] btnD = new System.Windows.Forms.Button[5];
for(int i=0;i<5;i++) { btnD[i] = new Button(); btnD[i].Text="Submit"; }
btnD[0].Text="Submit"; btnD[1].Text="Delete";
//I have a panel on the form //and controls will be added to it for (int i = 0; i < 5; i++) { string btnName = string.Format("Btn{0}", i.ToString()); Button btn = new Button(); btn.Name = btnName; btn.Left += i * 100; // you need to arrange them using some way panel1.Controls.Add(btn); } //Editing generated controls foreach (Control control in panel1.Controls) { if (control is Button) { //Change Text and Color and ... Button btn = (Button)control; btn.Text = control.Name; // or everything you want btn.Height = 20; btn.Width = 100; } }
private void Form1_Load(object sender, EventArgs e) { for (int i =1; i < 5; i++) { Button button1 = new Button(); button1.Location = new System.Drawing.Point(105 + 20 * i, 92 +20 * i); button1.Name = "button"+i; button1.Size = new System.Drawing.Size(75, 23 ); button1.TabIndex = 0+i; button1.Text = "button" + i; button1.UseVisualStyleBackColor = true; this.Controls.Add(button1); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)