Hello,
Product: PowerShell Studio 2022 (64 Bit)
Build: v5.8.210
OS: Windows Server 2016 Standard (64 Bit)
Build: v10.0.14393.0
I have a form with ckeckedlistbox, it contains many items generated by reading active directory attributes on users.
Can i hilight or text color or text forecolor on item that are checked ? It will add visibility to user on the form.
thanks.
Checkedlistbox change color when item checked
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.
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.
-
- Posts: 20
- Last visit: Thu Mar 09, 2023 4:36 am
- Has voted: 1 time
Re: Checkedlistbox change color when item checked
[Topic moved by moderator to PowerShell GUIs forum]
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Checkedlistbox change color when item checked
Just change the text color on the item object in the "Changed" event.
Right click the control in the toolbox to see the links to the documentation for any control including example code on the Sapien site.
Right click the control in the toolbox to see the links to the documentation for any control including example code on the Sapien site.
-
- Posts: 20
- Last visit: Thu Mar 09, 2023 4:36 am
- Has voted: 1 time
Re: Checkedlistbox change color when item checked
thanks for your answer. I might be dumb but i do not find how to do it
Any example to give me ?
Any example to give me ?
Re: Checkedlistbox change color when item checked
There is an event on any control that is triggered when the control is changed. You can find the "Changed" event for any control by right-clicking on the control in the toolbox.
-
- Posts: 20
- Last visit: Thu Mar 09, 2023 4:36 am
- Has voted: 1 time
Re: Checkedlistbox change color when item checked
i found msdn help
I already look into this but i don t find code example for the event i want to :
If item is checked -> text of item checked go to bold red
If item is not checked -> text return or stay default black
Really thanks for your time
I already look into this but i don t find code example for the event i want to :
If item is checked -> text of item checked go to bold red
If item is not checked -> text return or stay default black
Really thanks for your time
Re: Checkedlistbox change color when item checked
Sorry. The items in a checkedlistbox cannot have different colors. YOU would have to learn how to use the primitive graphics object and the graphics command to re-write the text in a custom color.
I don't have an example of that for this control. You can search for it on the web. There are numerous examples.
I still recommend by starting with the book I posted a link to. This will also help you start to understand WinForms with PowerShell. It will also help when you search for examples.
I don't have an example of that for this control. You can search for it on the web. There are numerous examples.
I still recommend by starting with the book I posted a link to. This will also help you start to understand WinForms with PowerShell. It will also help when you search for examples.
-
- Posts: 20
- Last visit: Thu Mar 09, 2023 4:36 am
- Has voted: 1 time
Re: Checkedlistbox change color when item checked
Here is a hint on how to do this.
This is for a ListBox but a CheckedList will work the same.
Attached is a demo but it is old. I wrote it a decade ago but the PS and WinForms haven't changed.
- $listbox1_DrawItem=[System.Windows.Forms.DrawItemEventHandler]{
- #Event Argument: $_ = [System.Windows.Forms.DrawItemEventArgs]
- $b = New-Object System.Drawing.SolidBrush($listbox1.Items[$_.Index].Color)
- $p = New-Object System.Drawing.PointF($_.Bounds.X, $_.Bounds.Y)
- $text=$listbox1.Items[$_.Index].Text
- $_.Graphics.DrawString($text,$_.Font,$b,$p)
- }
Attached is a demo but it is old. I wrote it a decade ago but the PS and WinForms haven't changed.
- Attachments
-
- Demo-ListboxDrawItem.psf
- (22.81 KiB) Downloaded 70 times
-
- Posts: 20
- Last visit: Thu Mar 09, 2023 4:36 am
- Has voted: 1 time
Re: Checkedlistbox change color when item checked
really really thanks !!!!
I discover Powershell language five month ago and i m not a dev ... for years i do some batch files, play with autoit and vbs but never learn how to code ...
i want to create a tool that help to manage accounts / groups / files / shares for multi user AD school (about 2000 users and 800 computers)
Do not laught when you see my code ... i try to my best but i know theres a lot of improvement to do in it . For today i do workable code but there is lots of repetitions, and i m sure there is functions i can made to simplify it.
I discover Powershell language five month ago and i m not a dev ... for years i do some batch files, play with autoit and vbs but never learn how to code ...
i want to create a tool that help to manage accounts / groups / files / shares for multi user AD school (about 2000 users and 800 computers)
Do not laught when you see my code ... i try to my best but i know theres a lot of improvement to do in it . For today i do workable code but there is lots of repetitions, and i m sure there is functions i can made to simplify it.
- Attachments
-
- modificationuser.psf
- (122.43 KiB) Downloaded 57 times