下面的代码示例获取对活动 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 (tempChild.Controls[i] is TextBox) { // 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 = "";
}
}
}