listbox items in different colors


Posted by Ralf on October 27, 2000 11:11 AM

Hi everybody,

nice to see that I'm not the only one with questions about Excel & VBA ...

I've been searching the whole web for some hints how to create a listbox with let's say every second item in a different color.

I still have no idea ... some out there who can help me?

Thanks a lot ... even if you say that it's impossible ...

Posted by Ivan Moala on October 27, 2000 4:05 PM


Hi Ralf
I don't think this is possible ???
The selector color for listboxs,dropdowns etc.
is determined by your Windows OS... you can change
this via API calls but this will change it for ALL
windows.......anyway here is how you can change it
by code;

'=Code Start =

Public Declare Function SetSysColors Lib "user32" _
(ByVal nChanges As Long, lpSysColor As Long, _
lpColorValues As Long) As Long


Public Const COLOR_HIGHLIGHT = 13 'Selected item background color


Sub SetColour(lngColour As Long)
' Set the system colour for the Selection Highlighter
SetSysColors 1, COLOR_HIGHLIGHT, lngColour
End Sub

Sub SetSys_Colour()
Dim R As Single
Dim G As Single
Dim B As Single

SetColour (RGB(0, 0, 0))
'Color Red Value Green Value Blue Value
'Black 0 0 0
'Blue 0 0 255
'Green 0 255 0
'Cyan 0 255 255
'Red 255 0 0
'Magenta 255 0 255
'Yellow 255 255 0
'White 255 255 255
End Sub


There are a number of syscolor constants the above is just one. If you would like a list
to see what you can change then post.


HTH

Ivan



Posted by Ralf on October 30, 2000 7:35 AM

Hi Ivan,

it seems to work, but you're right there are side-effects.

Anyway - great idea and thank you very much!

Ralf.