Public Sub ClearTextBoxes(ByVal Frm As Form)
Dim Ctl As Control
For Each Ctl In Frm.Controls
If TypeOf Ctl Is TextBox Then Ctl.Text = ""
If TypeOf Ctl Is GroupBox Then
Dim Ctl1 As Control
For Each Ctl1 In Ctl.Controls
If TypeOf Ctl1 Is TextBox Then
Ctl1.Text = ""
End If
Next
End If
Next
End Sub
我有这种方法,但问题是,我的组框出现在一个面板中,只是被这些控件混淆了很多。
答案 0 :(得分:3)
答案 1 :(得分:1)
这是一种方法:
Public Sub ClearTextBoxes(ByVal Frm As Form)
Dim Ctl As Control
For Each Ctl In Frm.Controls
If TypeOf Ctl Is TextBox Then Ctl.Text = ""
If TypeOf Ctl Is Panel Then
Dim Ctl1 As Control
For Each Ctl1 In Ctl.Controls
If TypeOf Ctl1 Is TextBox Then Ctl1.Text = ""
If TypeOf Ctl1 Is GroupBox Then
Dim Ctl2 As Control
For Each Ctl2 In Ctl1.Controls
If TypeOf Ctl2 Is TextBox Then Ctl2.Text = ""
Next
End If
Next
End If
Next
End Sub
它可能无法涵盖所有情况,但它适用于您告诉我们的内容。
答案 2 :(得分:0)
感谢您的所有建议,我得出结论,此代码对我来说非常适合。
Public Sub ClearTextBoxes(ByVal Frm As Form)
Dim Ctl As Control
For Each Ctl In Frm.Controls
If TypeOf Ctl Is TextBox Then Ctl.Text = ""
If TypeOf Ctl Is Panel Then
Dim Ctl1 As Control
For Each Ctl1 In Ctl.Controls
If TypeOf Ctl1 Is TextBox Then Ctl1.Text = ""
If TypeOf Ctl1 Is GroupBox Then
Dim Ctl2 As Control
For Each Ctl2 In Ctl1.Controls
If TypeOf Ctl2 Is TextBox Then Ctl2.Text = ""
Next
End If
Next
End If
If TypeOf Ctl Is GroupBox Then
Dim Ctl1 As Control
For Each Ctl1 In Ctl.Controls
If TypeOf Ctl1 Is TextBox Then
Ctl1.Text = ""
End If
Next
End If
Next
End Sub