0

So I have a form with a variety of different controls (combobox, textboxes, listboxes, etc).

My first thought is to create a If, Else, End If statement. Well while that would work, it could also get pretty long, depending on the amount of controls and combinations.

Validation could include if a listbox is filled, checkbox is checked, etc pertaining to WinForms.

Is there a better solution to check all possiblities than an If statement?

4

2 回答 2

1

在用户填写表单时进行错误检查可能是值得的。这可以通过 LostFocus 事件来实现。前任:

Private Sub btnTest_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles yourbutton.LostFocus
    Dim txt = yourbutton.Text
            If txt = "yourtest" Then
            'do stuff
            EndIf
End Sub
于 2012-09-27T21:39:18.260 回答
0

如上。这取决于您尝试执行的验证。您是否正在验证用户输入、数据类型长度范围等。您是否正在验证业务规则。某某值是否应该等于其他值。有各种各样的可能性。

于 2012-09-27T15:22:33.870 回答