我认为这个问题是如此简单和基本,我什么都无法工作。我只想验证用户输入,但我永远无法让验证规则仅在需要时触发。我试过使用获得焦点,失去焦点,离开和验证。其中一些在表单加载时触发,而其他字段查询时触发。我必须有一种简单的方法,希望您能理解并提供帮助。谢谢
请尝试将以下txtName.TextChanged作为事件,每次在文本框中更改值时都会运行。
Private Sub txtName_TextChanged(sender As Object, e As EventArgs) Handles txtName.TextChanged
End Sub
You can use the .net `ErrorProvider` and the `Validating` event.
Private err As New ErrorProvider()
Private Sub TextBox1_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If TextBox1.Text = "" Then
e.Cancel = True
err.SetError(TextBox1, "This text box cannot be blank.")
Else
err.Clear()
End If
End Sub