i have single tab page in form1 and a button is placed inside tab to open a childForm(Form2).... Form2 loads pefectly in tabpage1 on buttonclick ..... and now on ChildForm(Form2) i have another button to call For ChildForm(Form3) ...but somehow it doesn't Load..nor throw some error ....well here is my Code
public Form1//
private void LoadForm(object Form)
{
Form childForm = Form as Form;
childForm.TopLevel = false;
int curr = tabControl1.SelectedIndex;
TabPage tbp = tabControl1.TabPages[curr];
tabControl1.TabPages.Contains(tbp);
tbp.Controls.Add(childForm);
childForm.WindowState = FormWindowState.Maximized;
childForm.Show();
Refresh();
}
private void button1_Click(object sender, EventArgs e)
{
LoadForm(new Form2());
}
public void OpenForm();
{
LoadForm(new Form3());
}
Form2//
private void button1_Click(object sender, EventArgs e)
{
Form1 f = new Form1();
f.OpenForm(new Form3());
}
}enter image description here }
CodePudding user response:
public Form1//
private void LoadForm(object Form)
{
Form childForm = Form as Form;
childForm.TopLevel = false;
int curr = tabControl1.SelectedIndex;
TabPage tbp = tabControl1.TabPages[curr];
tabControl1.TabPages.Contains(tbp);
tbp.Controls.Add(childForm);
childForm.WindowState = FormWindowState.Maximized;
childForm.Show();
childForm.BringToFront();
Refresh();
}
private void button1_Click(object sender, EventArgs e)
{
LoadForm(new Form2());
}
public void OpenForm();
{
LoadForm(new Form3());
}
Form2//
static Form1 f1;
Public Form2( Form1 refer)
{ InitializeComponent();
f1 = refer;
}
private void button1_Click(object sender, EventArgs e)
{
f1.LoadForm();
}