0
Private Sub txtAddress_Leave (ByVal sender As Object, ByVal e As 
        System.EventArgs) Handles txtAddress.Leave
  If Len (txtAddress.Text) >= 0 Then
         MsgBox ("Need to enter address", MsgBoxStyle.OKOnly, _
         txtAddress.Focus()
  End if
End Sub

任何帮助,将不胜感激。

4

2 回答 2

3

我假设你想检查用户是否输入了文本,那么你应该改变这个

if Len (txtAddress.Text) >= 0 Then

if Len (txtAddress.Text) = 0 Then

但是,您应该更好地使用 .NET 方法:

If String.IsNullOrEmpty(txtAddress.Text) Then ' or String.IsNullOrWhiteSpace

您还应该使用Select而不是Focus.

txtAddress.Select()

textbox.Focus() 在 C# 中不起作用

于 2013-09-17T17:24:21.827 回答
0
If Len(txtAddress.Text) >= 0 Then

应该

If txtAddress.Text.Trim = "" Then

这样,如果有人决定只输入“空格”作为地址,它就会考虑在内。现在,如果他们确实输入了某些内容,您的代码将导致弹出消息框。

于 2013-09-17T17:31:23.853 回答