Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive

This video demonstrates how to work with the Tab Control GUI template using PowerShell Studio.

In this video you will learn how to:

  • Find the Tab Control template.
  • Add controls to the form.
  • Change control properties in the form.
  • Use Snippets code to add the code behind the form controls.

Additional Tips

Displaying output string to the Rich TextBox Control

The first time using the Rich TextBox control to display the results you will notice that the columns are misaligned. In order to display properly aligned columns, you need to go back to the Rich Textbox property in the Properties panel, select the Font property, and change it from Microsoft Sans Serif to Lucida Console.

TabControl 0o 2018 11 18 17 00 38

TabControl 02 2018 11 18 17 00 38 TabControl 03 2018 11 18 17 00 38

After you change the Font property, the string output to the Rich TextBox will look properly aligned:

TabControl 04 2018 11 18 17 00 38

In the Tab Control “Processes”, in the “Filter Process” textbox, use a process name shortname with the “*” asterisk wildcard.

sampleTabcontrol 062018 11 20 9 56 14

Create Snippet Code

As mentioned in the video, creating snippets is the best way to reuse existing code and also to create a library of reusable code for building new solutions.

Listed below is the code for the three snippets used in the sample Tab Control form:

## - Open Windows GUI to select only Folders using .NET object:
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog;
$FolderBrowser.RootFolder = "Desktop";

$Results = $FolderBrowser.ShowDialog();

if ($Results -eq "OK")
$location = $FolderBrowser.SelectedPath.ToString();
$textbox1.Text = $location;
## - Code use for Tab Control form ButtonOK
$Err01 = $null; $richtextbox1.Text = $null;
$GetDirectories = Get-ChildItem -Directory $textbox1.Text -ErrorVariable Err01 -ErrorAction SilentlyContinue

If ($Err01.Count -eq 0)
$richtextbox1.Text = $GetDirectories | Out-String -Width 1000;
## - Display error notification:
[void][System.Windows.Forms.MessageBox]::Show('Enter a valid folder Name!'+"`r`nError Message:`r`n$Err01", 'Invalid Folder Name');
$textbox1.Text = "Select or Enter folder name...";
## - Code use for Tab Control form Button3 OK
If ($textbox2.Text -eq '')
$GetProcesses = Get-process;
$richtextbox2.Text = $GetProcesses | Out-String -Width 1000;
$GetProcesses = Get-process $textbox2.Text;
$richtextbox2.Text = $GetProcesses | Out-String -Width 1000;

Feel free to download the SampleTabControlTemplate_11162018.

Related Article

If you have questions about our products, please post in our support forum.
For licensed customers, use the forum associated with your product in our Product Support Forums for Registered Customers.
For users of trial versions, please post in our Former and Future Customers - Questions forum.
Copyright © 2019 SAPIEN Technologies, Inc.