Results 1 to 5 of 5

Thread: [RESOLVED] [2005] ToolStripComboBox + Color selection

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Köln
    Posts
    395

    Resolved [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

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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:
    1. Dim namedColor As New KnownColor()
    2.         Dim allColors As Array = KnownColor.GetValues(namedColor.GetType)
    3.         Dim webColors As New List(Of String)
    4.         For Each webColor As Object In allColors
    5.             If Not (Color.FromKnownColor(CType(webColor, KnownColor)).IsSystemColor) Then
    6.                 webColors.Add(webColor.ToString)
    7.             End If
    8.         Next
    9.         ComboBox1.DataSource = webColors

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Köln
    Posts
    395

    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?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Köln
    Posts
    395

    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
  •  



Click Here to Expand Forum to Full Width