如何更改活动的 mdi 子项?

How to change the active mdi child?

好吧,这可能很简单,但我无法确定。
我有一个带有 n mdi childs 的 from as Mdi Container 的 win forms 应用程序。 如何设置 ActiveMdiChild ?
例如,我有 4 个 mdi 子项 (0,1,2,3),我想将适当的数据传递给每个子项...但只有活动项才能获取数据..

要激活特定的MDI child,您可以使用MDI parent 的ActivateMdiChild 方法,然后传递给child 来激活。例如:

 this.ActivateMdiChild(this.MdiChildren[0]);

ActivateMdiChild (Form)

Activates the MDI child of a form.

If the form parameter is already the active MDI child form, then the ActivateMdiChild method simply returns. If form is not null, then it is set to be the active MDI child form. Whether the form parameter is null or not, ActivateMdiChild raises the MdiChildActivate event.

你可以这样做:

  foreach (Form frm in this.MdiChildren)
        {
            if (frm is Form1)
            {
                Form frmChild = this.ActiveMdiChild;
                frmChild .Show();
            }
        }

如果 child 有不同的表单名称,您可以只使用 if 语句来检查这是否是您正在检查的表单,然后将其设置为您的 acitvemdichild.