
close
close
Want to know about the security benefits of Microsoft's E5 license?
In a previous article, I demonstrated how to add pop-up help for a WinForm-based PowerShell script using the ToolTip control. Because creating a WinForm script manually can be a tedious process, many IT pros find it useful to use a commercial product, such as PowerShell Studio from SAPIEN. You can download a free evaluation copy from SAPIEN.com. Let’s say that I have an existing project and want to add some ToolTip help. I want to use the same technique from my previous article, so check that out first before continuing.
I have my project open in PowerShell Studio. Find the ToolTip item in the control Toolbox.
Finding ToolTip item in SAPIEN PowerShell Studio. (Image Credit: Jeff Hicks)
Dropping the ToolTip control onto the form in SAPIEN PowerShell Studio. (Image Credit: Jeff Hicks)
$ShowHelp = {
#display popup help
#each value is the name of a control on the form.
Switch ($this.name)
{
"text1" { $tip = "help text here." }
}
$tooltip1.SetToolTip($this, $tip)
} #end ShowHelp
My template assumes you are using a ToolTip control called $ToolTip1. It shouldn’t really matter where you insert the command. Eventually I will copy and paste the switch statement for every control that I define.
Inserting a switch statement. (Image Credit: Jeff Hicks)
Selecting a control in SAPIEN PowerShell Studio. (Image Credit: Jeff Hicks)
Adding events in SAPIEN PowerShell Studio. (Image: Jeff Hicks)
Specifying the name of the ShowHelp script block. (Image Credit: Jeff Hicks)
Invoking the & operation to run the ShowHelp command. (Image Credit: Jeff Hicks)
Defining the associated scriptblock. (Image Credit: Jeff Hicks)
Exporting the project to a PowerShell script file. (Image Credit: Jeff Hicks)
$txtComputername.add_MouseHover($txtComputername_MouseHover)
As an alternative, I could modify the event to call ShowHelp directly.
$txtComputername.add_MouseHover($ShowHelp)
However, I would have had to wait until the final script was created to make the change. I could have set ToolTip help in each _MouseHover event handler, but personally I find my ShowHelp scritpblock easier to use because I can define all the help strings in one location. Ultimately, it depends on what you find easier to work with.
If you find yourself using my ShowHelp technique, you may want to save it as a snippet in PowerShell Studio to save some yourself from typing next time. Select the code in the script editor and right-click.
Creating a snippet in SAPIEN PowerShell Studio. (Image Credit: Jeff Hicks)
Dialog box for creating a snipped in SAPIEN PowerShell Studio. (Image Credit: Jeff Hicks)
Accessing script block from the Snippets menu. (Image Credit: Jeff Hicks)
More in PowerShell
Most popular on petri