Skip to content

ImageList

In a ScriptoForm, the ImageList the Microsoft .NET class is a component used to manage a collection of Image objects. An ImageList is typically used by other controls, such as the ListView, TreeView, or ToolBar. You can add bitmaps or icons to the ImageList, and the other controls are able to use the images as they require.
  1. Instantiate a new System.Windows.Forms.ImageList object in the Controls region.
  2. Set TransparentColor, ColorDepth, and ImageSize properties to the ImageList object (and/or other properties as needed) in the $ShowFormMain script block in the Forms region.
  3. Add images to ImageList.ImageCollection property of the ImageList object as needed. This might be peformed initially, in the $ShowFormMain script block in the Forms region, or within an Event Handler script block.
  4. Assign the ImageList component to a control, such as a ListView, in the $ShowFormMain script block in the Forms region.
PowerShell
# Create the ImageList and assign properties:
$ImageListMain = New-Object -TypeName System.Windows.Forms.ImageList
$ImageListMain.TransparentColor = [Drawing.Color]::Transparent
$ImageListMain.ColorDepth = [System.Windows.Forms.ColorDepth]::Depth32Bit
$ImageListMain.ImageSize = New-Object -TypeName System.Drawing.Size(32,32)
# Add files to the ImageList:
$ImageListMain.Images.Add([Drawing.Image]::FromFile($ToolPNGFile))
$ImageListMain.Images.Add([Drawing.Image]::FromFile($ScriptICOFile))
foreach ($IconFile in Get-ChildItem $CustomIconsLocation)
{
$ImageListMain.Images.Add($IconFile.BaseName,[System.Drawing.Icon]::ExtractAssociatedIcon($IconFile.FullName))
}
# Assign the ImageList to a control:
$ListViewMain.LargeImageList = $ImageListMain

The above example shows how to use an ImageList component to store images for use by a ListView control.

ImageList Class (System.Windows.Forms) | Microsoft Learn