PowerShell Studio: New Form Template

November 1st, 2012 by David Corrales
Last updated on November 1st, 2012

 

In the (v3.1.9) service release we introduced a new form template called: Wizard Template.

Wizard Template

This template simulates an application wizard by utilizing a TabControl to represent the various pages of the wizard. The template also includes navigation buttons that enable and disable depending on the current position and if the controls validate.

 

Wizard Tabs & Navigation

Each tab page has a sample input that must either be entered or checked in order to proceed.

For example, tab page “Step 1” has a textbox that must have information entered before proceeding:

Before Entering Text:

Enter Name Empty

The Next button is disabled.

 

After Entering Text:

Enter Name After

The Next button is enabled because the text box has passed validation.

 

The same applies to the other tab pages until the final page, which enables the Finish button once all the other pages are validated:

Final Page

 

Wizard Template Functions:

The template includes functions to handle navigation and provide a place to insert your custom validation script. This validation script is called whenever the user tries to navigate to the next page in the wizard.

Validate-WizardPage

This function is called whenever the Wizard needs to validate a TabPage. Place your custom validation code here. Return True if the page is valid otherwise False if validation fails. The Wizard calls this function when the user is navigating to another tab page. If the function returns a value of False it will prevent the user from proceeding. The result of this function also influences whether the Next and Finish buttons are enabled or disabled.

function Validate-WizardPage
{
<#
    Add TabPages and place the validation code in this function
#>
    [OutputType([boolean])]
    param([System.Windows.Forms.TabPage]$tabPage)
    
    if($tabPage -eq $tabpageStep1)
    {
        #TODO: Enter Validation Code here for Step 1
        if(-not $textboxName.Text)
        {
            return $false    
        }
        
        return $true
    }
    elseif ($tabPage -eq $tabpageStep2)
    {
        #TODO: Enter Validation Code here for Step 2
        if($checkboxCheckToContinue.Checked)
        {
            return $true
        }
        
        return $false
    }

 

Update-NavButtons

Call this function when you wish to validate the current page and update the states of the navigation buttons.

This function should be called when the state of a control changes and has influence on whether the user can continue or not. For example, in the “Step 1“  tab page, the Text Box must have text before proceeding; as a result, Update-NavButton is called whenever the TextBox’s text changes.

$textboxName_TextChanged={
    Update-NavButtons
}

In addition to validation, the Next, Back and Finish buttons are enabled or disabled depending on the current tab’s position.

 

Finish Button

Once all the tabs have been validated, the user can press the Finish Button. Place your custom script in the Finish button’s Click event to handle any finalization.

$buttonFinish_Click={
    #-------------------------------------------------------
    # TODO: Place finalization script here
    #-------------------------------------------------------
    
}

Note: The Finish button has its DialogResult property set to OK; therefore, it will close the form once the user clicks on the button.

 

For more details on the TabControl, please refer to the Spotlight on the TabControl blog article.
For more details on the Button control, please refer to the Spotlight on the Button Control blog article.

 

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

Tags: , , , ,