开发者

Show MDI child Always on top of other MDI child

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 prop开发者_运维百科erty 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 better solution that doesn't requiring changing every other form: - declare the new toolbox as a control of the Main Parent (this):

fForm fFormObj = new fForm();
fFormObj.TopLevel = false;
this.Controls.Add(fFormObj);
fFormObj.Parent = this;
fFormObj.TopMost = true;
fFormObj.Show();


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.


//Edit

Since only one of your MdiChild form needs to be focused, try the following:

In the MdiChildActivate event re-focus or re-activate the required window as the activated child window.

You could also use the Deactivated event to enforce the re-focusing of the concerned child window.

When you create the form and show it also append a call to focus method.

ChildForm.Focus()

Setting the focus should make it topmost.

Hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜