How do I find out which control has focus in winforms?
+1
A:
Something along these lines:
Protected Function GetFocusControl() As Control
Dim focusControl As Control = Nothing
' Use this to get the Focused Control:
Dim focusHandle As IntPtr = GetFocus()
If IntPtr.Zero.Equals(focusHandle) Then
focusControl = Control.FromHandle(focusHandle)
End If
' Note that it returns NOTHING if there is not a .NET control with focus
Return focusControl
End Function
I think this code came from windowsclient.net, but it's been a while so...
Stephen Wrighton
2009-03-18 21:36:43