VB version here.
This code will visit every control on a form, regardless of how deeply it's nested. You could have a TextBox in a Panel in a Splitter in a GroupBox in a TabPage in a TabControl in a Panel and it will still be found. No recursion is need on your part, as this will simply follow the tab order from start to finish. It also doesn't matter if a control has it's TabStop set to False, as it must still have a TabIndex.No doubt the GetNextControl method uses recursion internally, but that's not our concern. This will keep your code nice and neat and you'd need a very, very large number of controls before you'd notice a difference in performance.Code:Control ctl = this.GetNextControl(this, true); // Get the first control in the tab order. while (ctl != null) { // Use ctl here. ctl = this.GetNextControl(ctl, true); // Get the next control in the tab order. }




Reply With Quote