VB net 文本框为什么得不到焦点?

2025-04-23 21:15:53
推荐回答(4个)
回答1:

PRIVATE n AS integer
Private Sub Command6_Click()
    If Text1.Text <> "admin" Then
        MsgBox ("用户名不正确,程序退出!")
        End
    Else
        Do While n <= 3
           If Text2.Text <> "admin" Then
               Text2.Text = ""
               MsgBox "密码不正确,请重新输入"
     
               Text2.SetFocus
                 n = n + 1
               exit sub
           Else
               MsgBox ("密码输入正确,欢迎登陆")
               Exit Do
               End
           End If
        Loop
     End if
     If n > 3 Then
         MsgBox ("密码输入三次均无效,程序退出")
         End
     End if
End Sub

回答2:

在load事件时,窗体都还没有显示,怎么有焦点?焦点只有在show以后才可以产生,所以Raiuy的回答是可以的,在Activated事件中写

回答3:

应该是:
Me.activecontrol=Me.Textbox1

回答4:

试试看

Private Sub Form1_Activated(sender As Object, e As EventArgs) Handles MyBase.Activated

TextBox1.Focus()
End Sub