想一次将窗体中所有TextBox清空,遇到问题了。
为了达到一次清空所有TextBox的目的,查了很多资料。MSDN上是这样的:
' Visual Basic 2005
Private Sub ClearText(ByVal container As Control)
Dim ctrl As Control
For Each ctrl In container.Controls
If TypeOf (ctrl) Is TextBox Then
ctrl.Text = ""
End If
If ctrl.HasChildren Then
ClearText(ctrl)
End If
Next
End Sub
我的按钮中的代码是根据上面代码改的:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf (ctrl) Is TextBox Then
ctrl.Text = ""
End If
Next
End Sub
但是结果是清除不了,根本没有反应。
到底哪里错了呢?
谢谢!