Combobox with multiple colors

Outlook98 uses combo boxes with multiple color text for choosing colors to organize email.  Neither VB5 nor VB6 appear to support this functionality.

I have spent too much time looking for source code on the web and I don't want to use a third-party control [if one such exists].

Anybody have any source code to do this?  
Who is Participating?
watyConnect With a Mentor Commented:
you will find full source code to do that.
That's funny

According to Microsoft they violate their own rules :)

Excerpt from Article ID: Q141023

"Visual Basic doesn't directly support the display of text of different colors simultaneously in the list box. Multi-color list boxes do not adhere to GUI design standards and should
not be used."

You could try this:
Simulate the list box with a picture box control. You can store the desired text strings in an array of strings, and use the Print method to write the array entries into the picture box with different ForeColor properties. For example:

picture1.BackColor = QBColor(14)  ' 14=Light yellow
picture1.ForeColor = QBColor(4)   '  4=Red
picture1.Print "in living red"
picture1.ForeColor = QBColor(2)   '  2=Green
picture1.Print "in living green"

You can also add a vertical scroll bar next to the picture box. When the scroll bar is scrolled, your code needs to redraw the picture box. The ForeColor property of the picture box controls the current color used by the Print method. The picture box will not let you highlight text.
You could use a combination of click and mouseover to determine which item the user selected.

I know it is not what you were looking for, but you could make it work

I'm just posting as a comment, hopefully somebody else knows of an API call to do it:)


percosolatorAuthor Commented:
Maybe the key with the article is "List Box?".

Have seen multi-color text ComboBoxes, and ListViews.  Don't think that I have ever seen a multi-color text ListBox, though.

What do you think?

Really would like the combobox code, though.

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

.. this sounded fun, I'm just off to write such a box.. I'll let you know how it worked

percosolatorAuthor Commented:
Thanx.  'preciate it.
OK, paste this into a file, name it combo.frm and try it out.

The structure is
    a frame on the form, will always want to be set topmost.
    in the frame is a textbox at te top,
    beside the textbox is a scrollbar sitting real high so you juet see the down arrow,
    under the textbox is a picture box,
    when the drop down is not there, it is actually hidden by the resized frame.

The sizes worked out, work for a drop down with 10 items, with a little more work, it could handle a variable number of entries.

Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   4410
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6225
   LinkTopic       =   "Form1"
   ScaleHeight     =   4410
   ScaleWidth      =   6225
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame ComboFrame
      BorderStyle     =   0  'None
      Caption         =   "Frame1"
      Height          =   270
      Left            =   120
      TabIndex        =   1
      Top             =   240
      Width           =   2415
      Begin VB.PictureBox ComboPicture
         Height          =   2055
         Left            =   0
         ScaleHeight     =   1995
         ScaleWidth      =   2115
         TabIndex        =   2
         Top             =   240
         Width           =   2175
      Begin VB.VScrollBar ComboDownArrow
         Height          =   615
         Left            =   2160
         TabIndex        =   4
         Top             =   -370
         Width           =   255
      Begin VB.TextBox ComboText
         Height          =   285
         Left            =   0
         TabIndex        =   3
         Top             =   0
         Width           =   2175
   Begin VB.TextBox DebugText
      ForeColor       =   &H00000000&
      Height          =   375
      Left            =   2880
      TabIndex        =   0
      Top             =   480
      Width           =   1815
   Begin VB.Label Label1
      Caption         =   "Mouse Is Over:"
      Height          =   255
      Left            =   2880
      TabIndex        =   5
      Top             =   240
      Width           =   1215
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim TheArrayofColors(10)
Dim TheArrayofText(10)
Dim IsComboShowing As Boolean
Dim ComboWhichRowHasTheMouse As Integer
Sub Combo(Action As String)
    Dim i As Integer
    If Action = "Show" Then
        ComboFrame.Height = 2355
        IsComboShowing = True
        ComboPicture.BackColor = &HFFFFFF  'white
        For i = 0 To 9
            ComboPicture.ForeColor = TheArrayofColors(i)
            ComboPicture.Print TheArrayofText(i)
    End If
    If Action = "Hide" Then
        ComboFrame.Height = 270
        IsComboShowing = False
    End If
End Sub
Private Sub ComboPicture_LostFocus()
    Combo "Hide"
End Sub
Private Sub ComboPicture_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ComboWhichRowHasTheMouse = Y \ 195
    DebugText.Text = ComboWhichRowHasTheMouse
End Sub
Private Sub ComboPicture_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ComboText.Text = TheArrayofText(ComboWhichRowHasTheMouse)
    Combo "Hide"
End Sub
Private Sub ComboDownArrow_Change()
    If Not IsComboShowing Then
        Combo "Show"
        Combo "Hide"
    End If
End Sub
Private Sub Form_Load()
    TheArrayofColors(0) = &HFF&    'red
    TheArrayofColors(1) = &HFF0000 'blue
    TheArrayofColors(2) = &HFF00& 'green
    TheArrayofColors(3) = &HFF&   'red
    TheArrayofColors(4) = &HFF0000 'blue
    TheArrayofColors(5) = &HFF00& 'green
    TheArrayofColors(6) = &HFF&   'red
    TheArrayofColors(7) = &HFF0000 'blue
    TheArrayofColors(8) = &HFF00& 'green
    TheArrayofColors(9) = &HFF&   'red
    TheArrayofText(0) = "Line 0"
    TheArrayofText(1) = "Line 1"
    TheArrayofText(2) = "Line 2"
    TheArrayofText(3) = "Line 3"
    TheArrayofText(4) = "Line 4"
    TheArrayofText(5) = "Line 5"
    TheArrayofText(6) = "Line 6"
    TheArrayofText(7) = "Line 7"
    TheArrayofText(8) = "Line 8"
    TheArrayofText(9) = "Line 9"
End Sub

may be u can AddressOf operator to subclass the combobox and handle
the paint message by your own.
percosolatorAuthor Commented:

That's a VERY clever proposal.  Unfortunately, I have to reject it.  There are problems with the picture box and underlying controls (part of the underlying control is blanked out.)

And also if this were to be made into an OCX and simulate a combo, then there be a lot of coding to be implemented:  got focus, lost focus, ALT Down Arrow to drop the "combo", an item selector...

iDT, this solution showed me an alternative way of looking at the problem, and I would like to give you 50 pts and an "A" rating for the effort.  I am leaving you another "Question" for your proposed solution.

percosolatorAuthor Commented:
Thanks.  I realize that the pts were high for this, but I was really, really sick of looking!  :)

Bought This Question.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.