Solved

Combobox with multiple colors

Posted on 1999-01-17
10
311 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
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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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 200 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

822 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