In this question in the OS I think you have the answer you want. Correct me if I'm wrong. You are right in your statement. I highlight the first two answers there.
A method that scans the controls to find which one is in focus (I created it as an extension method since it can be very useful for all controls):
public static Control FindFocusedControl(this Control control) {
var container = control as IContainerControl;
while (container != null) {
control = container.ActiveControl;
container = control as IContainerControl;
}
return control;
}
How to use:
formulario.ActiveControl.FindFocusedControl();
Or it has a form using the Win32 API:
public class MyForm : Form {
[DllImport("user32.dll", CharSet=CharSet.Auto, CallingConvention=CallingConvention.Winapi)]
internal static extern IntPtr GetFocus();
private Control GetFocusedControl() {
Control focusedControl;
// 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;
}
}