|
-
Feb 20th, 2007, 07:43 AM
#1
Thread Starter
Hyperactive Member
[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
-
Feb 20th, 2007, 10:00 AM
#2
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
-
Feb 21st, 2007, 01:22 AM
#3
Thread Starter
Hyperactive Member
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?
-
Feb 21st, 2007, 01:32 AM
#4
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.
-
Feb 21st, 2007, 02:12 AM
#5
Thread Starter
Hyperactive Member
Re: [2005] ToolStripComboBox + Color selection
@jmcilhinney:
Thanks for your explanation and suggestion - i will try it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|