Different text colors for each item in a listbox

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
miketartaglia
Posts: 100
Joined: Mon Feb 02, 2015 7:44 am

Different text colors for each item in a listbox

Post by miketartaglia »

Is it possible to have different text colors for each item depending on an expression in a listbox? If so, please point me in the right direction .

Thank you,
Mike

jvierra
Posts: 14667
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: Different text colors for each item in a listbox

Post by jvierra »

Hi Mike. You can use the "DrawItem" event to customize the colors of the lines in a ListBox.

Code: Select all

$listbox1_DrawItem=[System.Windows.Forms.DrawItemEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.DrawItemEventArgs]
	
}

Locked