Solved

Combobox with multiple colors

Posted on 1999-01-17
10
298 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
Comment Utility
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
Comment Utility
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
Comment Utility
.. this sounded fun, I'm just off to write such a box.. I'll let you know how it worked

-iDT
0
 
LVL 2

Author Comment

by:percosolator
Comment Utility
Thanx.  'preciate it.
0
 
LVL 3

Expert Comment

by:idt
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Expert Comment

by:kianwei
Comment Utility
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
Comment Utility
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
Comment Utility
on http://www.geocities.com/ResearchTriangle/6311/
you will find full source code to do that.
0
 
LVL 2

Author Comment

by:percosolator
Comment Utility
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
Comment Utility
Bought This Question.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now