The ProgressBarOverlay Control
- Written by David Corrales
- Last Updated: 22 April 2016
- Created: 27 August 2012
- Hits: 7740
PowerShell Studio has a custom control called ProgressBarOverlay. This 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 article.