Hello,
I'm looking to list all web colors in a drop down so users can select it for my form.
I'll let write that color to a reg key, and load it thus making their selection permanant but messing with the colordialog, I can't seem to print them to a combobox
List all WebColors in a drop down
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.
- apowershelluser
- Posts: 194
- Last visit: Fri Mar 22, 2024 4:38 am
- apowershelluser
- Posts: 194
- Last visit: Fri Mar 22, 2024 4:38 am
Re: List all WebColors in a drop down
Gotcha, I just don't know how to display all of these colors..
I see there are some examples in C.. looks like I need to learn to read C lol
I see there are some examples in C.. looks like I need to learn to read C lol
Re: List all WebColors in a drop down
Add a ColorDialog to the designer and then set the following lines within your button's click event:
To get the result, use the Color property of the ColorDialog.
Code: Select all
$button1_Click={
if ($colordialog1.ShowDialog() -eq 'OK')
{
$color = $colordialog1.Color
}
}
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- apowershelluser
- Posts: 194
- Last visit: Fri Mar 22, 2024 4:38 am
Re: List all WebColors in a drop down
Thanks David.. But I'm looking for something like this
- Attachments
-
- ComboBox.png (94.88 KiB) Viewed 3522 times
Re: List all WebColors in a drop down
Here is a quick way of doing that:
Code: Select all
$colors = [System.Enum]::GetValues([System.Drawing.KnownColor]) | ForEach-Object { [System.Drawing.Color]::FromKnownColor($_) }
Update-ComboBox -ComboBox $comboboxColors -Items $colors
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: List all WebColors in a drop down
For web colors only this should be the correct enum:
For SystemColors just change to "[System.Drawing.SystemColors]".
Use David's method for "Windows Colors".
Code: Select all
(([System.Drawing.Color]).GetProperties()) |
Where-Object{ $_.PropertyType -eq [System.Drawing.Color] } |
Select-Object name
Use David's method for "Windows Colors".
- apowershelluser
- Posts: 194
- Last visit: Fri Mar 22, 2024 4:38 am
Re: List all WebColors in a drop down
I used a combination of both and it's working!
I'm so thankful
I'm so thankful
- $colors = ((([System.Drawing.Color]).GetProperties()) |
- Where-Object{ $_.PropertyType -eq [System.Drawing.Color] }).name
- $colors += ((([System.Drawing.SystemColors]).GetProperties()) |
- Where-Object{ $_.PropertyType -eq [System.Drawing.Color] }).name
- $colors = $colors | Sort-Object
- Update-ComboBox -ComboBox $combobox1 -Items $colors
Re: List all WebColors in a drop down
But now you have no way to decode them. You can't tell which one is from which enum. It will work on objects that can decode all colors by string name. Some objects only manage certain color types.
Re: List all WebColors in a drop down
Here is a quick and dirty sample of how to manage objects in a list/combo which can make colors easier.
We can also just draw a little sample of the color as an icon-like tag to the list.
In this demo the colors denote the type of the color string and the color objects are available.
We can also just draw a little sample of the color as an icon-like tag to the list.
In this demo the colors denote the type of the color string and the color objects are available.
- Attachments
-
- Demo=CBColors.psf
- (10.14 KiB) Downloaded 137 times