Skip to content

Custom Icon

The base ScriptoForm displays a default icon in two locations:
  • The title bar of the Form
  • The (optional) compiled executable file
Either, or both, of these icons can be changed to provide a custom appearance to the Form or compiled executable.
By default, the icon used for the Form will be that of the PowerShell version used with the script. This allows the user to easily identify which version of PowerShell is being used with the ScriptoForm:
  • Windows PowerShell 5.x
  • Windows PowerShell ISE
  • PowerShell 7.x
The icon is set by extracting it from the PowerShell process used with the script at runtime and applying it to the Form:
Forms Region | $ShowMainForm
$FormMain.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon((Get-Process -Id $PID).Path)
If you would like to provide a custom icon for the Form use the following steps:
  1. Copy the custom icon to the root of the ScriptoForm project folder.

  2. Edit the PowerShell script file of the project and change the following line:

    Forms Region | $ShowMainForm
    $FormMain.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon((Get-Process -Id $PID).Path)

    to:

    Forms Region | $ShowMainForm
    $FormMain.Icon = New-Object System.Drawing.Icon "$PSScriptRoot\iconname.ico"

    …where iconname.ico is the name of the custom icon file.

  3. Save the changes to the file.

If you also intend to compile the ScriptoForm into an executable you need to complete these additional steps:
  1. Edit the /Build/Build.csproj file and ADD the following lines of code to the <ItemGroup> section as follows, BELOW any existing embedded resources:
    Build.csproj
    <EmbeddedResource Include="..\iconname.ico">
    <LogicalName>iconname.ico</LogicalName>
    </EmbeddedResource>
    …where iconname.ico is the name of the custom icon file and must EXACTLY match the name used in the script file.
  2. Save the changes to the file.
  3. Recompile the executable.
By default, the icon used for the compiled executable file will be the generic form icon provided by the Microsoft .NET framework. If you intend to compile the ScriptoForm into an executable, and would like to provide a custom icon for the compiled executable file, use the following steps:
  1. Copy the custom icon to the “/Build” directory of the ScriptoForm project folder.

  2. Edit the /Build/Build.csproj file of the project and change the following line:

    Build.csproj
    <ApplicationIcon></ApplicationIcon>

    to:

    Build.csproj
    <ApplicationIcon>iconname.ico</ApplicationIcon>

    …where iconname.ico is the name of the custom icon file.

  3. Save the changes to the file.

  4. Recompile the executable.