/// <summary> /// Forces the keyboard focus to the given control, sending a TakeKeyboardFocus /// message to the specified control. If a control currently has the /// keyboard focus, that control will receive a ReleaseKeyboardFocus message. /// </summary> public void TakeKeyboard(Control control) { if (control == null) { throw new ArgumentNullException("control"); } if (control != CurrentKeyboardFocus) { control.OnTakeKeyboardFocus(); if (CurrentKeyboardFocus != null) { CurrentKeyboardFocus.OnReleaseKeyboardFocus(); } CurrentKeyboardFocus = control; } }
/// <summary> /// Base method propagates messages to children controls and managers. Override to /// add custom handling. /// </summary> protected internal override void OnMouseButtonDown(MouseData mouseData) { base.OnMouseButtonDown(mouseData); foreach (Manager m in managerList) { m.OnMouseButtonDown(mouseData); } // If applicable, forward MouseDown and Select to child control if (CurrentUnderMouse != null && CurrentUnderMouse.IsActive) { CurrentUnderMouse.OnMouseButtonDown(mouseData); LastLBDown = CurrentUnderMouse; } // Check to see if a control looses KBFocus if user hit any mouse button outside current focused control if (CurrentKeyboardFocus != null) { if (CurrentKeyboardFocus != CurrentUnderMouse) { CurrentKeyboardFocus.OnReleaseKeyboardFocus(); CurrentKeyboardFocus = null; } } // Give KBFocus to child on left button down, if applicable if (CurrentUnderMouse != null && CurrentUnderMouse.CanHaveKeyboardFocus && CurrentUnderMouse.HasKeyboardFocus == false && mouseData.MouseButton == MouseButton.LeftButton && CurrentUnderMouse.IsActive) { CurrentKeyboardFocus = CurrentUnderMouse; CurrentKeyboardFocus.OnTakeKeyboardFocus(); } }