TabPages are a great solution when working with Powershell GUI, especially in a case where you would like to have “multiple” actions in one script on one hand, without loading too much information and controls in one place on the other hand.
In this blog, I will review a very simple way to handle a situation where you have already build your TabPages in a specific order, but then you have in mind a new TabPage that forced you to rearrange the TabPages order.
The GUI Form
I built a very basic form to demonstrate the problem and solution of TabPages reordering.
The form contains 2 TabPages:
- tabPage1 with a label contains the sentence Tab 1 Label
- tabPage2 with a label contains the sentence Tab 2 Label
The labels were added just to demonstrate that reordering the TabPages, reorder the whole TabPage, including all the properties attached without changing or replacing anything else which related to the same TabPage.
So, this is what it looks like, a form with 2 TabPages, while tabPage1 is the first in order and the next one, is tabPage2:
The script behind the form will show us that $tabControl1.Controls.Add($tabPage1) which is associate to tabPage1, is the first TabPage in the list before $tabControl1.Controls.Add($tabPage2) which is the second TabPage:
Replacing the order between the two inside the script, as the following example:
Will simply replace the TabPages order and all their associates :
That’s it, as simple as that!