简体   繁体   English

显示MDI子项始终位于其他MDI子项之上

[英]Show MDI child Always on top of other MDI child

How do I show a MDIChild Form always on top of other MDIChild Forms ? 如何显示总是在其他MDIChild表单之上的MDIChild表单?

I have set TopMost property of the ChildForm to True, But the form still behaves the same way... 我已经将ChildForm的TopMost属性设置为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." 我试图将ChildForm的TopLevel属性设置为True,并收到错误消息...“无法更改父控件的顶级样式。”

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): 一个更好的解决方案,不需要更改其他任何形式:-声明新的工具箱作为Main Parent的控件 (此):

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: 该框架显然不支持彼此拥有的MDI子窗口,因此您必须自己模拟该行为:

  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. 我通常只是使拥有的表单不是MDI子表单。 They don't stay in the MDI container, but at least they stay in front. 它们不会停留在MDI容器中,但至少它们会停留在前面。

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. 可能存在此限制的原因是,当作为所有者的MDI子代在容器内最大化时,所期望的奇怪或模棱两可的行为。 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: 由于只需要重点放在您的MdiChild表单之一,请尝试以下操作:

In the MdiChildActivate event re-focus or re-activate the required window as the activated child window. MdiChildActivate事件中,将焦点重新聚焦或重新激活所需的窗口作为已激活的子窗口。

You could also use the Deactivated event to enforce the re-focusing of the concerned child window. 您还可以使用Deactivated事件来强制相关子窗口重新聚焦。

When you create the form and show it also append a call to focus method. 创建表单并显示它时,还要附加对focus方法的调用。

 
 
 
  
  ChildForm.Focus()
 
  

Setting the focus should make it topmost. 设置焦点应使其位于最上方。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM