Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void SelectNextTextBox()
- {
- TextBox newTextBox = null;
- if (_currentTextBox == keyText1)
- {
- newTextBox = keyText2;
- }
- else if (this._currentTextBox == keyText2)
- {
- newTextBox = keyText3;
- }
- else if (this._currentTextBox == keyText3)
- {
- newTextBox = keyText4;
- }
- else if (this._currentTextBox == keyText4)
- {
- newTextBox = keyText5;
- }
- else if (this._currentTextBox == this.keyText5)
- {
- newTextBox = regText1;
- }
- else if (this._currentTextBox == regText1)
- {
- newTextBox = regText2;
- }
- else if (this._currentTextBox == regText2)
- {
- newTextBox = regText3;
- }
- else if (this._currentTextBox == regText3)
- {
- newTextBox = regText4;
- }
- else if (this._currentTextBox == regText4)
- {
- newTextBox = regText5;
- }
- else
- {
- return;
- }
- newTextBox.SelectAll();
- newTextBox.Focus();
- }
- // global mapping
- private Dictionary<TextBox, TextBox> nextTextboxMap = new Dictionary<TextBox, TextBox>();
- private void InitNextTextBoxMap()
- {
- this.nextTextboxMap[keyText1] = keyText2;
- this.nextTextboxMap[keyText2] = keyText3;
- this.nextTextboxMap[keyText3] = keyText4;
- // add the other mappings here
- // where key = current textbox, and value = next textbox.
- }
- private void SelectNextTextBox()
- {
- TextBox newTextBox = null;
- if (this.nextTextboxMap.TryGetValue(this._currentTextBox, out newTextBox))
- {
- newTextBox.SelectAll();
- newTextBox.Focus();
- // Maybe you also want to reset this._currentTextBox at this point?
- // this._currentTextBox = newTextBox;
- }
- }
- TextBox[] allTextBoxes = new TextBox[]{
- keyText1,
- keyText2,
- keyText3,
- keyText4,
- keyText5,
- regText1,
- regText2,
- regText3
- };
- int currentIndex = Array.IndexOf(allTextBoxes, this._currentTextBox);
- if(currentIndex > 0)
- {
- int nextIndex = (currentIndex + 1) % allTextBoxes.Length;
- TextBox nextTextBox = allTextBoxes[nextIndex];
- nextTextBox.SelectAll();
- nextTextBox.Focus();
- }
- List<TextBox> boxes;
- int boxesIndex;
- boxes = new List<TextBox>(); // Then add each text box to list from first to last.
- boxesIndex = -1;
- if(boxes == null || boxes.Count == 0)
- throw new Exception("No textboxes have been set");
- Textbox tb;
- if(++boxesIndex >= boxes.Count)
- {
- boxesIndex = 0;
- }
- tb = boxes[boxesIndex];
- tb.SelectAll();
- tb.Focus();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement