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.
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:
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).
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:
If you just want to use the underlying function, select the Set-ControlTheme snippet.
This snippet contains the Set-ControlTheme function.
All the magic happens within the Set-ControlTheme function. The function has three parameters:
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.
The Theme parameter determines the theme to apply to the specified control. The two theme choices are:
Dark
Light
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:
There are some limitations to the themes.
Scrollbars are not skinned. The scrollbars are rendered by the OS and utilize the system's theme.
The calendar control's colors cannot be overwritten, so the control will retain its light color.
Like the scroll bar, the ProgressBar's rendering is handled by the OS.