VB.Net .Clear() or txtbox.Text = “” textbox clear methods

后端 未结 8 841
囚心锁ツ
囚心锁ツ 2021-01-11 13:49

Not far into programming and just joined this forum of mighty company so this is a silly question, but what is the best way to clear textboxes in VB.Net and what is the diff

8条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-11 14:41

    Add this code in the Module :

    Public Sub ClearTextBoxes(frm As Form) 
    
        For Each Control In frm.Controls
            If TypeOf Control Is TextBox Then
                Control.Text = ""     'Clear all text
            End If       
        Next Control
    
    End Sub
    

    Add this code in the Form window to Call the Sub routine:

    Private Sub Command1_Click()
        Call ClearTextBoxes(Me)
    End Sub
    

提交回复
热议问题