Form.ActiveMdiChild 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取当前活动的多文档界面 (MDI) 子窗口。
public:
property System::Windows::Forms::Form ^ ActiveMdiChild { System::Windows::Forms::Form ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Form ActiveMdiChild { get; }
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.Form? ActiveMdiChild { get; }
[<System.ComponentModel.Browsable(false)>]
member this.ActiveMdiChild : System.Windows.Forms.Form
Public ReadOnly Property ActiveMdiChild As Form
属性值
返回表示当前活动的 MDI 子窗口的 Form,或者如果当前没有子窗口,则返回 null
。
- 属性
示例
以下示例获取对活动 MDI 子窗体的引用,并循环访问窗体上的所有 TextBox 控件,并重置其 Text 属性。 此示例要求已创建 MDI 父窗体,并且此方法调用是从 MDI 父窗体进行的。
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 ( dynamic_cast<TextBox^>(tempChild->Controls[ i ]) )
{
// Clear the contents of the control since it is a TextBox.
tempChild->Controls[ i ]->Text = "";
}
}
}
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 = "";
}
}
}
Public Sub ClearAllChildFormText()
' Obtain a reference to the currently active MDI child form.
Dim tempChild As Form = Me.ActiveMdiChild
' Loop through all controls on the child form.
Dim i As Integer
For i = 0 To tempChild.Controls.Count - 1
' Determine if the current control on the child form is a TextBox.
If TypeOf tempChild.Controls(i) Is TextBox Then
' Clear the contents of the control since it is a TextBox.
tempChild.Controls(i).Text = ""
End If
Next i
End Sub
注解
可以使用此方法来确定 MDI 应用程序中是否打开了任何 MDI 子窗体。 还可以使用此方法从 MDI 父窗体或应用程序中显示的另一个窗体对 MDI 子窗口执行操作。
如果当前活动窗体不是 MDI 子窗体,则可以使用该 ActiveForm 属性获取对它的引用。