简单的问题。我有一个名为lblName的标签和一个名为txtName的文本框。如果在文本框中输入数字,如何使标签字体显示为红色。
答案 0 :(得分:1)
Private Sub txtName_TextChanged(sender As Object, e As EventArgs) Handles txtName.TextChanged
' Gets the text from the text box.
Dim text As String = txtName.Text
' Checks if the entered text is a number (Only numbers).
If IsNumeric(text) Then
' Change the label fore color to red.
lblName.ForeColor = Color.Red
Else
' If the text is not a number, change the color back to black.
lblNamge.ForeColor = Color.Black
End If
End Sub