PowerShell Studio: New ProgressBar Control
In the last service release of PowerShell Studio 2012 (v3.0.8) a new custom control called ProgressBarOverlay was introduced. This new progress control functions exactly like the typical progress bar, with the added ability of displaying a text percentage over the progress bar.
Adding a ProgressBarOverlay Control:
Like the typical progress bar, you can add the new progress bar control using the ToolBox Pane:
The new control offers full designer support as you would expect from a normal progress bar:
By default, the ProgressBarOverlay control displays the current percentage. This value is calculated using the progress bar’s Value and Maximum properties. As you step or directly modify the progress bar’s Value, the control will automatically update to reflect the current percentage.
Note: The percentage will not be displayed if the ProgressBar’s Style property is set to Marquee.
Displaying Alternate Text:
In certain cases you may want to display text instead of a percentage; particularly when using the Marquee style in instances where the progress is unknown. In order to display custom text, the ProgressBarOverlay control has a property called:
Set this property in order to display custom text over on the progress bar.
The Custom Control in Exported Script:
PowerShell has the ability to compile C# code on demand by use the Add-Type cmdlet. This powerful feature allows us to create and utilize customs control directly in the exported script.
When the script is executed, it checks if the custom type is already defined. If the custom type is not defined, the script will call the Add-Type cmdlet to compile the code on demand. Once the type is defined, the script can instantiate and use the custom control:
For further help on using the progress bar, please refer to the Spotlight on the ProgressBar Control blog.