Results 1 to 8 of 8

Thread: [RESOLVED] how can i load and display colors in a combobox?

  1. #1

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,132

    Resolved [RESOLVED] how can i load and display colors in a combobox?

    hey
    i have 11 colors that i want it to be in a combobox
    any idea how to do this ?
    Code:
        Private HairColor(11) As Long
        HairColor(1) = RGB(164, 189, 252)
        HairColor(2) = RGB(122, 234, 191)
        HairColor(3) = RGB(219, 173, 255)
        HairColor(4) = RGB(231, 231, 214)
        HairColor(5) = RGB(251, 215, 91)
        HairColor(6) = RGB(255, 184, 120)
        HairColor(7) = RGB(70, 214, 219)
        HairColor(8) = RGB(225, 225, 225)
        HairColor(9) = RGB(84, 132, 237)
        HairColor(10) = RGB(81, 183, 73)
        HairColor(11) = RGB(220, 33, 39)
    name of combobox is Cmbcolor

    tnx in advanced
    salsa

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,409

    Re: how can i load and display colors in a combobox?

    If you are not dead-set on a combobox, but would settle for a listbox....here is an EXCELLENT example of how to color individual items in a listbox....http://www.vb6.us/tutorials/indepth-...stbox-tutorial (search for "color", it's a long article about the listbox).

    Sammi

  3. #3
    Hyperactive Member
    Join Date
    Oct 2016
    Posts
    369

    Re: how can i load and display colors in a combobox?

    You could use an ImageComboBox

  4. #4
    Frenzied Member gibra's Avatar
    Join Date
    Oct 2009
    Location
    ITALY
    Posts
    1,695

    Re: how can i load and display colors in a combobox?

    You can use a ImageCombo but this control doesn't support directly the colors, images only are supported (stored into ImageList).
    So, you need to create the image of colors 'on fly' .

    Create a new VB6 project.

    Toolbox: add a Microsoft Windows Common Controls 6.0 (SP6)
    Form1: add a ImageCombo control , name imgCboColors
    Form1: add a PictureBox, name Picture1
    Form1: add a ImageList, name ImageList1

    Paste the below code in Form1:

    Code:
    Public Sub LoadImgComboColors()
        Dim i As Long
        Dim sKey(1 To 5) As String, lColor(1 To 5) As Long
        
        imgCboColors.ComboItems.Clear
        ImageList1.ListImages.Clear
        
        sKey(1) = "Yellow": lColor(1) = vbYellow
        sKey(2) = "Red": lColor(2) = vbRed
        sKey(3) = "Magenta": lColor(3) = vbMagenta
        sKey(4) = "Blue": lColor(4) = vbBlue
        sKey(5) = "Green": lColor(5) = vbGreen
        
        For i = 1 To 5
        
            ' Create a picture with color
            With Picture1
                .Cls
                .AutoRedraw = True
                .FillStyle = vbFSSolid
                .FillColor = lColor(i)
                Picture1.Line (0, 0)-(480, 480), lColor(i), BF
                .Picture = .Image
            End With
            ' add picture to ImageList
            ImageList1.ListImages.Add i, sKey(i), Picture1.Picture
            
            imgCboColors.ImageList = ImageList1
            
            ' create a combo item with color
            imgCboColors.ComboItems.Add , sKey(i), sKey(i), i
        
        Next i
        
        imgCboColors.ComboItems(1).Selected = True
    End Sub
    
    Private Sub Form_Load()
        Picture1.Visible = False
        Picture1.Move 0, 0, 300, 300
        LoadImgComboColors
    End Sub

  5. #5

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,132

    Re: how can i load and display colors in a combobox?

    tnk you amigos i got it

  6. #6

  7. #7
    Hyperactive Member
    Join Date
    Oct 2016
    Posts
    369

    Re: [RESOLVED] how can i load and display colors in a combobox?

    Salsa must have a short memory. From Nine months ago http://www.vbforums.com/showthread.p...=1#post5030923

    Not to mention the same answers were posted

  8. #8

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,132

    Re: [RESOLVED] how can i load and display colors in a combobox?

    Quote Originally Posted by I Love VB6 View Post
    Salsa must have a short memory. From Nine months ago http://www.vbforums.com/showthread.p...=1#post5030923

    Not to mention the same answers were posted
    yeah getting old

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