internal void SetFocus(Control control)
{
// Rekursiver Aufruf
foreach (var child in Children.InZOrder())
child.SetFocus(control);
bool hit = (control == this);
if (focused != hit)
{
EventArgs args = new EventArgs();
if (hit)
{
// Unsichtbare und nicht fokusierbare Elemente ignorieren
if (!Visible || !CanFocus || !Enabled)
return;
focused = true;
// Fokus gerade erhalten
OnGotFocus(args);
if (GotFocus != null)
GotFocus(this, args);
}
else
{
focused = false;
// Fokus gerade verloren
OnLostFocus(args);
if (LostFocus != null)
LostFocus(this, args);
}
InvalidateDrawing();
}
}