[RESOLVED] [2005] ToolStripComboBox + Color selection
Greetings,
I like to fill a ToolStripCombobox with a list of colors.
The colors should be the list Web you get in the IDE Property Window when you select any color property.
Is there any easy way to get this colors into a ToolStripComboBox?
many thanks in advance
Re: [2005] ToolStripComboBox + Color selection
Hi, try this code. It'll popuplate ComboBox1 with all the knowncolors that are not system colors (thus the list is left with web colors)
VB Code:
Dim namedColor As New KnownColor()
Dim allColors As Array = KnownColor.GetValues(namedColor.GetType)
Dim webColors As New List(Of String)
For Each webColor As Object In allColors
If Not (Color.FromKnownColor(CType(webColor, KnownColor)).IsSystemColor) Then
webColors.Add(webColor.ToString)
End If
Next
ComboBox1.DataSource = webColors
Re: [2005] ToolStripComboBox + Color selection
@stanav:
first thanks it works on fine on a combobox. For a ToolStripComboBox I had to change it, because the ToolStripComboBox has no DataSource.
But it is only part I wanted to do. I was thinking of getting the colors next to the text. So the user can see the color as well.
As far I can figure it out has the ToolStripComboBox only one Item.Add Methode. So I am not sure if this is to achive with the ToolStripComboBox. The only think I can imagin is to put the colors instead the text into the list?
Re: [2005] ToolStripComboBox + Color selection
The ToolStripComboBox is NOT a control. It is a container for a ComboBox control. You can get access to the hosted control via the Control property. I'm guessing that that would allow you to set the DataSource property if you had to, but Items.AddRange should be enough.
The ComboBox control doesn't natively support displaying a colour swatch or anything else alongside an item. There are numerous examples of inherited classes customising the ComboBox to display images or colour swatches.
Your problem is that the ToolStripComboBox hosts a vanilla ComboBox and there's nothing you can do about that, so what do you do? You don't use the ToolStripComboBox class at all. It's just a class that inherits ToolStripControlHost and hosts a ComboBox. You inherit the ComboBox class to provide the custom functionality you want, then you inherit the ToolStripControlHost to create a host for your custom ComboBox.
Re: [2005] ToolStripComboBox + Color selection
@jmcilhinney:
Thanks for your explanation and suggestion - i will try it.