public static bool SetFocusToNext <T>(Block current) where T : Block { while (current != null) { current = current.FindNextFocusableBlock(); if (current != null && current is T) { current.SetFocus(true); return(true); } } return(false); }
protected override void Children_KeyDown(Block block, System.Windows.Forms.KeyEventArgs e) { Block nextFocusable = null; if (e.KeyCode == System.Windows.Forms.Keys.Home) { nextFocusable = this.FindFirstFocusableBlock(); if (nextFocusable != null) { nextFocusable.SetCursorToTheBeginning(); e.Handled = true; } } else if (e.KeyCode == System.Windows.Forms.Keys.End) { nextFocusable = this.FindLastFocusableChild(); if (nextFocusable != null) { nextFocusable.SetCursorToTheEnd(); e.Handled = true; } } else if (e.KeyCode == System.Windows.Forms.Keys.Return) { Block next = this.Next; if (next != null) { nextFocusable = next.FindFirstFocusableBlock(); if (nextFocusable == null) { nextFocusable = nextFocusable.FindNextFocusableBlock(); } if (nextFocusable != null) { nextFocusable.SetFocus(); e.Handled = true; } } } if (!e.Handled) { base.Children_KeyDown(block, e); } }
/// <summary> /// One of the children of this LinearContainerBlock has received a key click. /// </summary> /// <param name="Block">Which child has been clicked?</param> /// <param name="e">Key event info</param> protected virtual void Children_KeyDown(Block block, System.Windows.Forms.KeyEventArgs e) { Block nextFocusable = null; bool isLeft = e.KeyCode == System.Windows.Forms.Keys.Left; bool isUp = e.KeyCode == System.Windows.Forms.Keys.Up; bool isDown = e.KeyCode == System.Windows.Forms.Keys.Down; bool isRight = e.KeyCode == System.Windows.Forms.Keys.Right; bool isPrev = e.KeyCode == PrevKey; bool isNext = e.KeyCode == NextKey; bool prevIsUp = PrevKey == System.Windows.Forms.Keys.Up; bool nextIsDown = NextKey == System.Windows.Forms.Keys.Down; if (isPrev || (isLeft && prevIsUp)) { nextFocusable = block.FindPrevFocusableBlock(); if (nextFocusable != null) { if (isLeft) { nextFocusable.SetCursorToTheEnd(); } else { nextFocusable.SetFocus(); } e.Handled = true; } else { if (this.CanGetFocus) { this.SetFocus(); e.Handled = true; } } } else if (isNext || (isRight && nextIsDown)) { nextFocusable = block.FindNextFocusableBlock(); if (nextFocusable != null) { if (isRight) { nextFocusable.SetCursorToTheBeginning(); } else { nextFocusable.SetFocus(); } e.Handled = true; } } else if (e.KeyCode == System.Windows.Forms.Keys.Home) { if (this.CanGetFocus) { this.SetFocus(); e.Handled = true; } } if (!e.Handled) { this.RaiseKeyDown(e); } }