PowerShell Studio: New ProgressBar Control

August 27th, 2012 by David Corrales
Last updated on August 27th, 2012

 

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:

ToolBox

 

The new control offers full designer support as you would expect from a normal progress bar:

ProgressBarOverlay in Designer

 

Displaying Percentage:

Displaying Percentage

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:

TextOverlay on ProgressBar

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:

TextOverlay  

Set this property in order to display custom text over on the progress bar.

TextOverlay in Property Pane

 

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.

Defining the Custom Control with Add-Type

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:

Instantiating the Custom Control

 

For further help on using the progress bar, please refer to the Spotlight on the ProgressBar Control blog.

 

 
[Google+]   [Facebook]   [LinkedIn]   [StumbleUpon]   [Digg]   [Reddit]   [Google Bookmark]  

Tags: , , , ,

Comments are closed.