internal void FocusActiveControlInternal()
{
if (active_control != null && active_control.Visible)
{
// Avoid focus loops, especially with ComboBoxes, on Win98/ME.
IntPtr focusHandle = XplatUI.GetFocus();
if (focusHandle == IntPtr.Zero || Control.FromChildHandle(focusHandle) != active_control)
{
XplatUI.SetFocus(active_control.Handle);
}
}
else
{
// Determine and focus closest visible parent
ContainerControl cc = this;
while (cc != null && !cc.Visible)
{
Control parent = cc.Parent;
if (parent != null)
{
cc = parent.GetContainerControl() as ContainerControl;
}
else
{
break;
}
}
if (cc != null && cc.Visible)
{
XplatUI.SetFocus(cc.Handle);
}
}
}