Check for empty TextBox controls in VB.NET

前端 未结 7 1875
离开以前
离开以前 2020-12-06 13:01

Ive got a Form application in VB.NET.

I have many text boxes on one form (about 20). Is there anyway to check them all at once to see if they are empty instead of wr

7条回答
  •  萌比男神i
    2020-12-06 13:08

    Public Class freestyle

    Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
        If Trim(TextBox3.Text) = "" And Me.Visible Then
            MsgBox("fill in the textbox")
            TextBox3.BackColor = Color.Yellow
    
    
        Else
            ' MsgBox("great one !!!")
    
        End If
    End Sub
    
    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
        If Trim(TextBox2.Text) = "" And Me.Visible Then
            MsgBox("fill in the textbox")
            TextBox2.BackColor = Color.Yellow
    
    
        Else
            'MsgBox("great one !!!")
    
        End If
    End Sub
    
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
    
    
        If Trim(TextBox1.Text) = "" Or Trim(TextBox2.Text) = "" Or Trim(TextBox3.Text) = "" And Me.Visible Then
            MsgBox("Please fill the necesary", MsgBoxStyle.Critical, "Error")
            TextBox1.Focus()
    
        Else
            MsgBox("Nice Work !!!")
        End If
    
    End Sub
    
    Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles TextBox1.Leave
        If Trim(TextBox1.Text) = "" And Me.Visible Then
            MsgBox("fill in the textbox")
            TextBox1.BackColor = Color.Yellow
    
    
        Else
            ' MsgBox("great one !!!")
    
        End If
    End Sub
    

    End Class

提交回复
热议问题