Ejemplo n.º 1
0
 /// <summary>
 /// Sets focus to child controls
 /// </summary>
 /// <param name="component">Child control</param>
 /// <param name="update">If set to true, then redraws the current panel</param>
 public virtual void SetFocus(Control component, bool update = true)
 {
     if (FocusedComponent != component)
     {
         if (FocusedComponent != null)
         {
             FocusedComponent.Focused = false;
             FocusedComponent.Update(false);
         }
         FocusedComponent  = component;
         component.Focused = true;
         if (update)
         {
             Update(false);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles button clicks
        /// </summary>
        /// <param name="keyInfo">ConsoleKeyInfo instance</param>
        public override void OnKeyPress(ConsoleKeyInfo keyInfo)
        {
            switch (keyInfo.Key)
            {
            case ConsoleKey.Tab:
                if (keyInfo.Modifiers == ConsoleModifiers.Shift)
                {
                    SetFocus(FocusPrevious());
                }
                else
                {
                    SetFocus(FocusNext());
                }
                break;

            case ConsoleKey.Enter:
                FocusedComponent?.OnKeyPress(keyInfo);
                if ((FocusedComponent == null || !(FocusedComponent is Button)) && Enter)
                {
                    OnEnter();
                }
                else if (FocusedComponent is Button button)
                {
                    OnButtonClick(button);
                }
                break;

            case ConsoleKey.Escape:
                FocusedComponent?.OnKeyPress(keyInfo);
                if (Escape)
                {
                    OnEscape();
                }
                break;

            default:
                FocusedComponent?.OnKeyPress(keyInfo);
                break;
            }
        }