سلام اگه درست فهمیده باشم میخواید از فرم1 به فرم 2 کنترل اضافه کنید
**نکته خیلی مهم:**خاصیت Modifiers کنترل TabControl رو باید روی public بذارید.
سورس کامل:
[CSHARP]using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Form2 frm = new Form2();
public Form1()
{
InitializeComponent();
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
if (listBox1.SelectedIndex != -1)
{
string title = (string)listBox1.SelectedItem;
TabPage myTabPage = new TabPage(title);
frm.tabControl1.TabPages.Add(myTabPage);
//create button and it's event
Button button1 = new Button();
button1.Click += new System.EventHandler(button1_Click);
button1.Location = new Point((myTabPage.Width / 2) - (button1.Width / 2), myTabPage.Height - 30);
button1.Text = "Click On Me!";
button1.AutoSize = true;
myTabPage.Controls.Add(button1);
//create button and it's event
Button button2 = new Button();
button2.Click += new System.EventHandler(button2_Click);
button2.Location = new Point((myTabPage.Width / 2) - (button1.Width / 2)+button1.Width+20, myTabPage.Height - 30);
button2.Text = "Close Tab";
button2.AutoSize = true;
myTabPage.Controls.Add(button2);
//Add textbox control to new tabpage
TextBox textBox1 = new TextBox();
textBox1.Location = new Point(5, 5);
textBox1.Text = "type some text...";
textBox1.Multiline = true;
textBox1.Height = button1.Top - 10;
textBox1.Width = myTabPage.ClientRectangle.Width - 10;
myTabPage.Controls.Add(textBox1);
}
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("You Clicked on me!");
}
private void button2_Click(object sender, EventArgs e)
{
frm.tabControl1.TabPages.Remove(frm.tabControl1.SelectedTab);
}
private void btnShow_Click(object sender, EventArgs e)
{
frm.Text = "Softafzar.net";
frm.Show();
}
}
}
[/CSHARP]
پروژه هم پیوست شد.