Solved

Combobox with multiple colors

Posted on 1999-01-17
10
315 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Getting warning: You are about to delete 1 row(s) 9 52
vb6 - Transfer from MSHFlexgrid1 to xls issue 8 54
Problem to With line 4 63
Excel Automation VBA 19 88
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

856 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