能告诉我VB中Validate事件的Cancel参数,是做什么用的吗?
我没用过VB:>

解决方案 »

  1.   

    这里给出 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
      

  2.   

      但是,我发现如果你单击其他按钮,其他按钮还是有效的,只是 Text1 保持焦点。我暂时没有其他办法了。这个是 VB 升级向导的解决方法,恐怕……
      

  3.   

      在 Throw New System.Exception() 前加上 MessageBox.Show("You can't leave this empty!", "Error", MessageBox.IconExclamation BitOr MessageBox.OK)。但是,如果用户通过快捷键,仍然 TMD 可以避开 Validating。我快疯了。
      

  4.   

    我哪里会呀,你认识的是子夜里面那个Ninputer吧,我们又不是同一个人