Setting a child form on top of another that has been activated

  • Thread starter Thread starter Jose Egea
  • Start date Start date
J

Jose Egea

Hello:
I have two child forms fChild1 and fChild2, and I want to set and reactivate
fChild2 over fChild1 when fChild1 is activated. I have tried with this code
in frmChild1, but it doesn't work, and now I dont't have any idea about how
to do it.
Can anybody help me, please?
Thanks in advance

private frmChild2 fChild2;
private void button1_Click(object sender, System.EventArgs e)
{
fChild2=new frmChild2();
fChild2.MdiParent=this.MdiParent ;
fChild2.Show();
}
private void frmChild1_Activated(object sender, System.EventArgs e)
{
if (!(fChild2==null))
{
fChild2.TopMost=true;
fChild2.BringToFront();
}
}
 
Jose said:
Hello:
I have two child forms fChild1 and fChild2, and I want to set and reactivate
fChild2 over fChild1 when fChild1 is activated. I have tried with this code
in frmChild1, but it doesn't work, and now I dont't have any idea about how
to do it.
Can anybody help me, please?
Thanks in advance

private frmChild2 fChild2;
private void button1_Click(object sender, System.EventArgs e)
{
fChild2=new frmChild2();
fChild2.MdiParent=this.MdiParent ;
fChild2.Show();
}
private void frmChild1_Activated(object sender, System.EventArgs e)
{
if (!(fChild2==null))
{
fChild2.TopMost=true;
fChild2.BringToFront();
}
}

MDI is a concept where there is no topmost or modal form. Any form visible
is part of a global UI which has to be accessable by the user. If you don't
want that, you shouldn't use MDI but SDI with for example dockable windows.

FB
 
Hi Jose,

Instead of using TopMost, call Activate on fChild2;

Happy coding!
Morten Wennevik [C# MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top