How do I find out which control has focus in .NET Windows Forms?

前端 未结 7 1200
逝去的感伤
逝去的感伤 2020-12-03 21:06

How do I find out which control has focus in Windows Forms?

7条回答
  •  粉色の甜心
    2020-12-03 21:30

    I used following:

    Private bFocus = False
    Private Sub txtUrl_MouseEnter(sender As Object, e As EventArgs) Handles txtUrl.MouseEnter
        If Me.ActiveControl.Name <> txtUrl.Name Then
            bFocus = True
        End If
    End Sub
    
    Private Sub txtUrl_MouseUp(sender As Object, e As MouseEventArgs) Handles txtUrl.MouseUp
        If bFocus Then
            bFocus = False
            txtUrl.SelectAll()
        End If
    End Sub
    

    I set the Variable only on MouseEnter to improve the magic

提交回复
热议问题