I have an MDI form with treeview on the left and form to appear on the right with splitter towards left side. I want to open a form based on the user click on the node within treeview how do I do it properly. The problem is that when I open new form a random one pops up on the screen for a milisecond and then it disappears, and the one that mean to appear is showing straight after. Here is my code so far:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
CloseAllMdiChildForms();
if (e.Node.Name == "root")
{
CustomerFrm cf = new CustomerFrm();
cf.Show();
cf.MdiParent = this;
}
//treeView1.MouseClick();
//if (treeView1.SelectedNode.Level == 0)
//{
// CustomerFrm CF = new CustomerFrm();
// CF.ShowDialog();
//}
}
There is a random form visible only for a millisecond appearing on the screen without reason. What's the problem?
The flicker is because you first show the form and then set its MdiParent
. So it flickers; it shows outside the mdi area and then after setting its MdiParent
it shows in mdi client area.
To solve the problem, it's enough to first set cf.MdiParent = this;
and then call cf.Show();
.