?
Solved

Combobox with multiple colors

Posted on 1999-01-17
10
Medium Priority
?
342 Views
Last Modified: 2013-12-25
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?  
0
Comment
Question by:percosolator
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 3

Expert Comment

by:idt
ID: 1489728
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:)

-iDT

0
 
LVL 2

Author Comment

by:percosolator
ID: 1489729
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.


0
 
LVL 3

Expert Comment

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

-iDT
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Author Comment

by:percosolator
ID: 1489731
Thanx.  'preciate it.
0
 
LVL 3

Expert Comment

by:idt
ID: 1489732
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.


VERSION 5.00
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
      End
      Begin VB.VScrollBar ComboDownArrow
         Height          =   615
         Left            =   2160
         TabIndex        =   4
         Top             =   -370
         Width           =   255
      End
      Begin VB.TextBox ComboText
         Height          =   285
         Left            =   0
         TabIndex        =   3
         Top             =   0
         Width           =   2175
      End
   End
   Begin VB.TextBox DebugText
      ForeColor       =   &H00000000&
      Height          =   375
      Left            =   2880
      TabIndex        =   0
      Top             =   480
      Width           =   1815
   End
   Begin VB.Label Label1
      Caption         =   "Mouse Is Over:"
      Height          =   255
      Left            =   2880
      TabIndex        =   5
      Top             =   240
      Width           =   1215
   End
End
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.Cls
        ComboPicture.BackColor = &HFFFFFF  'white
        For i = 0 To 9
            ComboPicture.ForeColor = TheArrayofColors(i)
            ComboPicture.Print TheArrayofText(i)
        Next
        ComboPicture.SetFocus
    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)
    ComboText.SetFocus
    Combo "Hide"
End Sub
Private Sub ComboDownArrow_Change()
    If Not IsComboShowing Then
        Combo "Show"
    Else
        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


-iDT
0
 

Expert Comment

by:kianwei
ID: 1489733
may be u can AddressOf operator to subclass the combobox and handle
the paint message by your own.
0
 
LVL 2

Author Comment

by:percosolator
ID: 1489734
iDT:

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.

Percosolator
0
 
LVL 14

Accepted Solution

by:
waty earned 800 total points
ID: 1489735
on http://www.geocities.com/ResearchTriangle/6311/
you will find full source code to do that.
0
 
LVL 2

Author Comment

by:percosolator
ID: 1489736
Thanks.  I realize that the pts were high for this, but I was really, really sick of looking!  :)


0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1489737
Bought This Question.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question