Tab Control vb.net中的清除文本框

时间:2015-03-06 15:00:15

标签: vb.net textbox tabcontrol

  • 我有一个包含3个标签页的标签控件。
  • 每个标签页都包含一个组框。
  • 每个“组”框包含不同的控件。

我想要发生的是,当用户点击按钮时,所有标签页中的所有文本框都会被清除。

我使用了这段代码:

    For Each page As TabPage In TB_Emp.TabPages
        For Each ctl As Control In page.Controls
            If TypeOf ctl Is TextBox Then
                ctl.Text = ""
            End If
            If TypeOf ctl Is ComboBox Then
                ctl.Text = ""
            End If
            If ctl.HasChildren Then
                For Each thing As Control In ctl.Controls
                    If TypeOf thing Is TextBox Then
                        thing.Text = ""
                    End If
                Next
            End If
        Next
    Next

但它只在第一个标签页上工作,我想在所有标签控制页面上应用此代码

1 个答案:

答案 0 :(得分:-1)

尝试循环遍历.TabPages集合中的控件:

Dim tp as TabPage

For Each tp in Tabs.TabPages

For Each ctrl In tp.Controls

'Check for textbox etc.

Next

Next

希望有所帮助

您也可以使用此LINK

试试这个

 foreach (Control c in tabPage1.Controls)
            {
                if (c.GetType() == typeof(TextBox))
                {
                    c.Text = string.Empty;
                }
            }