[DllImport("user32.dll")]
static extern IntPtr GetFocus();
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function GetFocus() As IntPtr
End Function
None.
None.
Method for getting WinForm Control associated with the focused window:
public static Control GetFocusedControl()
{
Control focusedControl = null;
// To get hold of the focused control:
IntPtr focusedHandle = GetFocus();
if(focusedHandle != IntPtr.Zero)
{
// Note that if the focused Control is not a .Net control, then this will return null.
focusedControl = Control.FromHandle(focusedHandle);
}
return focusedControl;
}
Please add some!
Do you know one? Please contribute it!