当用户在文本框中键入或删除文本时,我试图检查文本框是否为空。我已经尝试过几乎每个事件和一系列不同类型的检查,看它是否为空,但它只是没有注册。
我正在做的是验证,当用户修改输入时,它会在文本框下方的标签中显示验证文本,例如" Good","必须大于0& #34;,"不能留空#34;,"必须是数字",依此类推。
如果有任何不同,我会使用Ghost主题。
答案 0 :(得分:0)
我非常抱歉,但我已经活了两天多了。错误是如此之小,我疲惫的大脑没有注意到它。我在第1行有false
而不是true
。抱歉浪费你的时间。
Private Sub tbTime_TextChanged(sender As Object, e As EventArgs) Handles tbTime.TextChanged
labelTimeBetween.Visible = True
If String.IsNullOrEmpty(tbTime.Text) = True Then
labelTimeBetween.Text = "Musn't be empty"
labelTimeBetween.ForeColor = Color.Red
Return
End If
If String.IsNullOrEmpty(tbTime.Text) = False And IsNumeric(tbTime.Text) = False Then
labelTimeBetween.Text = "Numbers only"
labelTimeBetween.ForeColor = Color.Red
Return
End If
If CInt(tbTime.Text) = 0 Then
labelTimeBetween.Text = "Must be > 0"
labelTimeBetween.ForeColor = Color.Red
Return
End If
labelTimeBetween.Text = "Good"
labelTimeBetween.ForeColor = Color.Lime
End Sub