Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. private void SelectNextTextBox()
  2. {
  3. TextBox newTextBox = null;
  4.  
  5. if (_currentTextBox == keyText1)
  6. {
  7. newTextBox = keyText2;
  8. }
  9. else if (this._currentTextBox == keyText2)
  10. {
  11. newTextBox = keyText3;
  12. }
  13. else if (this._currentTextBox == keyText3)
  14. {
  15. newTextBox = keyText4;
  16. }
  17. else if (this._currentTextBox == keyText4)
  18. {
  19. newTextBox = keyText5;
  20. }
  21. else if (this._currentTextBox == this.keyText5)
  22. {
  23. newTextBox = regText1;
  24. }
  25. else if (this._currentTextBox == regText1)
  26. {
  27. newTextBox = regText2;
  28. }
  29. else if (this._currentTextBox == regText2)
  30. {
  31. newTextBox = regText3;
  32. }
  33. else if (this._currentTextBox == regText3)
  34. {
  35. newTextBox = regText4;
  36. }
  37. else if (this._currentTextBox == regText4)
  38. {
  39. newTextBox = regText5;
  40. }
  41. else
  42. {
  43. return;
  44. }
  45. newTextBox.SelectAll();
  46. newTextBox.Focus();
  47. }
  48.  
  49. // global mapping
  50. private Dictionary<TextBox, TextBox> nextTextboxMap = new Dictionary<TextBox, TextBox>();
  51.  
  52. private void InitNextTextBoxMap()
  53. {
  54. this.nextTextboxMap[keyText1] = keyText2;
  55. this.nextTextboxMap[keyText2] = keyText3;
  56. this.nextTextboxMap[keyText3] = keyText4;
  57. // add the other mappings here
  58. // where key = current textbox, and value = next textbox.
  59. }
  60.  
  61. private void SelectNextTextBox()
  62. {
  63. TextBox newTextBox = null;
  64. if (this.nextTextboxMap.TryGetValue(this._currentTextBox, out newTextBox))
  65. {
  66. newTextBox.SelectAll();
  67. newTextBox.Focus();
  68.  
  69. // Maybe you also want to reset this._currentTextBox at this point?
  70. // this._currentTextBox = newTextBox;
  71. }
  72. }
  73.  
  74. TextBox[] allTextBoxes = new TextBox[]{
  75. keyText1,
  76. keyText2,
  77. keyText3,
  78. keyText4,
  79. keyText5,
  80. regText1,
  81. regText2,
  82. regText3
  83. };
  84.  
  85. int currentIndex = Array.IndexOf(allTextBoxes, this._currentTextBox);
  86.  
  87. if(currentIndex > 0)
  88. {
  89. int nextIndex = (currentIndex + 1) % allTextBoxes.Length;
  90. TextBox nextTextBox = allTextBoxes[nextIndex];
  91. nextTextBox.SelectAll();
  92. nextTextBox.Focus();
  93. }
  94.  
  95. List<TextBox> boxes;
  96. int boxesIndex;
  97.  
  98. boxes = new List<TextBox>(); // Then add each text box to list from first to last.
  99. boxesIndex = -1;
  100.  
  101. if(boxes == null || boxes.Count == 0)
  102. throw new Exception("No textboxes have been set");
  103.  
  104. Textbox tb;
  105. if(++boxesIndex >= boxes.Count)
  106. {
  107. boxesIndex = 0;
  108. }
  109.  
  110. tb = boxes[boxesIndex];
  111. tb.SelectAll();
  112. tb.Focus();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement