OK, let's say I have a tab control (tabControl1) which contains one tab page (tabPage1) when I start the program. Inside tabPage1 I have some random stuff (look at the code)... when I click button1 i want to create a new exact copy of tabPage1.. so,
ok, so here is what makes up tabControl1 with tabPage1:
as you see there is some random controls in there like radio button and picture box and so on...
this code is the properties for those controls:
if I would like to create a new tab with the exact same content at the same position when i click a button (button1) I could do like this:
Now, finally to my point, there will be alot of code by doing this, and my question is; is there any easier way to do this? like copying tab1 in some way?
Thx in advance
ok, so here is what makes up tabControl1 with tabPage1:
Code:
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Location = new System.Drawing.Point(12, 12);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(251, 183);
this.tabControl1.TabIndex = 1;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.radioButton1);
this.tabPage1.Controls.Add(this.pictureBox1);
this.tabPage1.Controls.Add(this.textBox1);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(243, 157);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "tabPage1";
this.tabPage1.UseVisualStyleBackColor = true;
this code is the properties for those controls:
Code:
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(6, 6);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(126, 20);
this.textBox1.TabIndex = 0;
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.Black;
this.pictureBox1.Location = new System.Drawing.Point(50, 64);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(100, 50);
this.pictureBox1.TabIndex = 2;
this.pictureBox1.TabStop = false;
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.Location = new System.Drawing.Point(65, 120);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(85, 17);
this.radioButton1.TabIndex = 3;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "radioButton1";
this.radioButton1.UseVisualStyleBackColor = true;
Code:
private void button2_Click(object sender, EventArgs e)
{
int x = tabControl1.TabCount + 1;
TabPage tab = new TabPage("Tab " + x.ToString());
RadioButton rad = new RadioButton();
TextBox text = new TextBox();
PictureBox pic = new PictureBox();
//
// textBox1
//
text.Location = new System.Drawing.Point(6, 6);
text.Size = new System.Drawing.Size(126, 20);
text.TabIndex = 0;
//
// pictureBox1
//
pic.BackColor = System.Drawing.Color.Black;
pic.Location = new System.Drawing.Point(50, 64);
pic.Size = new System.Drawing.Size(100, 50);
pic.TabIndex = 2;
pic.TabStop = false;
//
// radioButton1
//
rad.AutoSize = true;
rad.Location = new System.Drawing.Point(65, 120);
rad.Size = new System.Drawing.Size(85, 17);
rad.TabIndex = 3;
rad.TabStop = true;
rad.Text = "radioButton1";
rad.UseVisualStyleBackColor = true;
tab.Controls.Add(rad);
tab.Controls.Add(text);
tab.Controls.Add(pic);
tabControl1.TabPages.Add(tab);
}
Thx in advance




