I have a form called frmTest1 with a splitcontainer with two panels. Panel 2 should load many forms one at a time. It works fine for the first form, but the second form cant then load a third form into panel 2 of frmTest1.
Here is stripped frmTest 1 code:
namespace Project1
{
public partial class frmMain3 : Form
{
public frmMain3()
{
InitializeComponent();
}
private void btnShowTest1_Click(object sender, EventArgs e)
{
showScreen(new frmTest1());
}
public void showScreen(Control ctl)
{
while (splitContainer1.Panel2.Controls.Count > 0)
splitContainer1.Panel2.Controls[0].Dispose();
if (ctl is Form)
{
var frm = ctl as Form;
frm.TopLevel = false;
frm.FormBorderStyle = FormBorderStyle.None;
frm.Visible = true;
}
ctl.Dock = DockStyle.Fill;
splitContainer1.Panel2.Controls.Add(ctl);
}
}
}
The second form's code is below:
namespace Project1
{
public partial class frmTest1 : Form
{
public frmTest1()
{
InitializeComponent();
}
private void btnShowTest4_Click(object sender, EventArgs e)
{
frmMain3 main = new frmMain3();
main.showScreen(new frmTest4()); //Nothing shows
}
}
}
From the research I have done it seems the solution is to use a usercontrol but having never used it before, I am struggling. Can someone please show me how to resolve this?