tags:

views:

41

answers:

2

How do I show a MDIChild Form always on top of other MDIChild Forms ?

I have set TopMost property of the ChildForm to True, But the form still behaves the same way...

I have tried to set TopLevel property of ChildForm to True and got the error message... "Top-level Style of a Parented control cannot be changed."

How do I achieve this.

Thanks

A: 
Vaibhav
I believe Focus will bring the Form to active status and will display it over all other forms... But when user changes the focus to some other MDIChild form, this form will get hidden behind that form... In short I want to achieve Always on Top, but restricted within my MDIChild windows
The King
Ok, now i get the clearer picture. My solution should work for 1 time focusing of the form. Thanks for clarifying!
Vaibhav
When I use the Activate code on ActivateEvent of form2 as said by BlueMonk it works... But when I use the Deactivate / Leave event of this (top) form, it is not working...
The King
+1  A: 

The framework apparently does not support MDI child windows owning each other so you have to simulate that behavior yourself:

  static Form f1 = new Form();
  static Form f2 = new Form();
  static Form f3 = new Form();

  [STAThread]
  static void Main()
  {
     f1.IsMdiContainer = true;
     f2.MdiParent = f1;
     f3.MdiParent = f1;
     f1.Show();
     f2.Show();
     f3.Show();
     f2.Activated += new EventHandler(f2_Activated);
     Application.Run(f1);
  }

  static void f2_Activated(object sender, EventArgs e)
  {
     f3.Activate();
  }

I generally just make owned forms not be MDI child forms. They don't stay in the MDI container, but at least they stay in front.

Perhaps the reason this limitation exists is because of the strange or ambiguous desired behavior when the MDI child that is the owner is maximized within the container. the above code will allow the owned form to go behind the maximized parent if you click on it in this case. If you have it outside the container, though, then it will remain visible.

BlueMonkMN
Your code works good... But the sad part is I have to wire this event for every other form of my application.
The King
There is also an event on the MDI parent when a child is activated.
BlueMonkMN