这里给出 VB 代码,由于都是 WinForms,所以 C# 代码类似,关键就是一个 Throw New System.Exception()。同志,请加分。
Private Sub Text1_Validating(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs)
Dim Cancel As Boolean = False
If Len(Text1.Text) = 0 Then
Cancel = True
End If
If Cancel Then
Throw New System.Exception()
End If
End Sub