I see a gray form and I want it painted black!
- Details
- Written by David Corrales
- Last Updated: 09 October 2019
- Created: 05 June 2019
- Hits: 8288
Have you stared at your GUI and thought to yourself, I want it painted black?
I have good news! No colors anymore! Now you can paint it black (and white), with new themes for your PowerShell GUIs.
This feature is included with PowerShell Studio v5.6.164 or greater.
New Form Template
If you creating a new form, you can select the new Dark and Light Themed Form template:
The new template comes with a MenuStrip that contains a theme dropdown:
Paint it Black
Select the Dark theme option, and it will paint your form black:
Paint it White
Select the Light theme option, and it will paint your form white:
Note: The designer will not reflect the themed colors. The themes are applied at runtime when the Set-ControlTheme function is invoked (see below).
New Control Set
Have an existing form? You can use the new Form – Dark and Light Theme control set to add a theme menu strip to your existing form:
New Snippet
If you just want to use the underlying function, select the Set-ControlTheme snippet.
This snippet contains the Set-ControlTheme function.
The Set-ControlTheme Function
All the magic happens within the Set-ControlTheme function. The function has three parameters:
Parameters:
Control
The Control parameter accepts a GUI control, typically the form itself. The function will then apply the theme to the control, and any child controls contained within.
Theme
The Theme parameter determines the theme to apply to the specified control. The two theme choices are:
Dark
Light
CustomColor
The CustomColor parameter allows you to specify a HashTable that contains user-defined colors for the theme. This parameter overrides the selected theme's default coloring.
Keys to override theme colors (optional):
WindowColor
Overrides the background color for the ListBox, TreeView, and grids controls.
ContainerColor
Overrides the background color for panels and other container controls such as the form.
BackColor
Overrides the background color for the controls.
ForeColor
Overrides the text color for the controls.
BorderColor
Overrides the border color for buttons, menus, and grid controls.
SelectionForeColor
Overrides the selection foreground color for the DataGrid and DataGridView.
SelectionBackColor
Overrides the selection background color for the DataGrid and DataGridView.
MenuSelectionColor
Overrides the color of menu items when a user selects or hovers over them.
Example:
#Override the Dark theme's Border and Selection colors
$hash = @{
BorderColor = 'DodgerBlue'
SelectionBackColor = 'DimGray'
}
Set-ControlTheme $form1 -Theme Dark -CustomColor $hash
Results in the following theme:
Limitations
There are some limitations to the themes.
ScrollBars
Scrollbars are not skinned. The scrollbars are rendered by the OS and utilize the system's theme.
MonthCalendar Control
The calendar control's colors cannot be overwritten, so the control will retain its light color.
ProgressBar Control
Like the scroll bar, the ProgressBar's rendering is handled by the OS.
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.