显示MDI子总是在其他MDI子顶部是在、MDI

2023-09-04 04:57:50 作者:如此放纵′为了谁

我如何显示MDIChild表单总是在其他MDIChild窗体顶端?

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

我已经设置了ChildForm为True TopMost属性,但形式仍然进行同样的操作...

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

我试图设置ChildForm为True的顶层财产,得到了错误的信息。一个与父母控制不能改变的顶级风格。

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."

我如何做到这一点。

感谢

推荐答案

该框架显然不支持MDI子窗口拥有对方,所以你必须来模拟自己的行为:

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();
  }

我一般只是让所有的形式不是MDI子窗体。他们没有停留在MDI容器,但至少他们留在前面。

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.

也许,这限制存在的原因是因为陌生或不明确的期望行为的时候,MDI子是店主在容器内被最大化。上述code将使所有的形式去最大化的父母身后,如果你在这种情况下点击就可以了。如果你有它在容器外,虽然,那么它将保持可见。

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.