I have a custom control, a function works for many years. Recently, I changed the inheritance from UserControl to Control. The function fails to return my expected result. How to modify to be the same?
Code:
public partial class UC: UserControl
to:
Code:
public partial class UC: Control
Code:
private bool IsUCOrChildrenFocused()
{
IntPtr hWnd = NativeMethods.GetFocus();
return (hWnd == base.Handle) || (NativeMethods.GetParent(hWnd) == base.Handle) || (NativeMethods.GetParent(NativeMethods.GetParent(hWnd)) == base.Handle);
}
Edited: The custom control contains one textbox and one combobox.
For "public partial class UC: UserControl" case, when the TextBox is visible and Focused then .Visible = False, IsUCOrChildrenFocused will return true; but for "public partial class UC: Control", IsUCOrChildrenFocused always returns false.