Form.ActiveMdiChild 属性属性值 返回表示当前活动的 MDI 子窗口的 Form,或者如果当前没有子窗口,则返回空引用(Visual Basic 中为 Nothing)。备注 可使用此方法确定 MDI 应用程序中是否有任何打开的 MDI 子窗体。也可使用此方法从 MDI 子窗口的 MDI 父窗体或者从应用程序中显示的其他窗体对该 MDI 子窗口执行操作。如果当前活动窗体不是 MDI 子窗体,则可使用 ActiveForm 属性获得对它的引用。示例 [Visual Basic, C#] 下面的示例获得对活动 MDI 子窗体的引用,并依次通过该窗体上的所有 TextBox 控件,重置这些控件的 Text 属性。此示例假定已经创建 MDI 父窗体,而且从该 MDI 父窗体执行此方法调用。[C#] public void ClearAllChildFormText() { // Obtain a reference to the currently active MDI child form. Form tempChild = this.ActiveMdiChild;
// Loop through all controls on the child form. for (int i = 0; i < tempChild.Controls.Count; i++) { // Determine if the current control on the child form is a TextBox. if (tempChild.Controls[i] is TextBox) { // Clear the contents of the control since it is a TextBox. tempChild.Controls[i].Text = ""; } } }
D:\C#练习\Noped\Form1.cs(508): 在不带括号的情况下引用了方法“System.Windows.Forms.Form.ActivateMdiChild(System.Windows.Forms.Form)”
D:\C#练习\Noped\Form1.cs(514): 在不带括号的情况下引用了方法“System.Windows.Forms.Form.ActivateMdiChild(System.Windows.Forms.Form)”
是不是要获得所有打开的MDI子窗体啊?
返回表示当前活动的 MDI 子窗口的 Form,或者如果当前没有子窗口,则返回空引用(Visual Basic 中为 Nothing)。备注
可使用此方法确定 MDI 应用程序中是否有任何打开的 MDI 子窗体。也可使用此方法从 MDI 子窗口的 MDI 父窗体或者从应用程序中显示的其他窗体对该 MDI 子窗口执行操作。如果当前活动窗体不是 MDI 子窗体,则可使用 ActiveForm 属性获得对它的引用。示例
[Visual Basic, C#] 下面的示例获得对活动 MDI 子窗体的引用,并依次通过该窗体上的所有 TextBox 控件,重置这些控件的 Text 属性。此示例假定已经创建 MDI 父窗体,而且从该 MDI 父窗体执行此方法调用。[C#]
public void ClearAllChildFormText()
{
// Obtain a reference to the currently active MDI child form.
Form tempChild = this.ActiveMdiChild;
// Loop through all controls on the child form.
for (int i = 0; i < tempChild.Controls.Count; i++)
{
// Determine if the current control on the child form is a TextBox.
if (tempChild.Controls[i] is TextBox)
{
// Clear the contents of the control since it is a TextBox.
tempChild.Controls[i].Text = "";
}
}
}