Getting background color of a listbox cell

In one of the listboxes in my app a row may require having a highlighting color background. The problem is that I want to ensure that the text is still readable. In a canvas or bevelbutton, I can detect the backcolor and reset the text color. But how can I get the listbox’s row backcolor when I go to show the cell’s text? My thought was to somehow access the backcolor in the CellTextPaint event and reset the text color there. But I can’t seem to find a way, in the CellTextPaint event, to determine the cell’s or row’s background color.

I thought to get the backcolor from ActiveCell but that won’t work since it is actually a temporary textfield. I could build an array of row colors to check in the CellTextPaint event but I really would rather not do it that way. Alternatively, I could build an array of text colors in the CellBackgroundPaint event but I’d rather not use that approach either if I don’t have to.

So, is there a way to easily determine the cell’s backgound color, preferably from the CellTextPaint event?

I’m not sure I understand the problem. Are you setting the background color yourself in CellBackgroundPaint? If not, it would only be different if the row is selected, and you can easily check that along with the selection color.

If you are setting it yourself, you already know what the color is, no?

Not trying to be snarky, just trying to better understand the issue.

If you set the Background color, store the value in a window (or module) property so you can check it when you want.

In a ProBono application I set two colors (light yellow and light blue), and in the preferences window I let the user set its own colors / reset these colors to my defaults. These colors are saved in the Prefs file (when ? I forgot if it was in the Pres close or Application Close), loaded at application Open time.

[quote=291139:@Kem Tekinay]I’m not sure I understand the problem. Are you setting the background color yourself in CellBackgroundPaint? If not, it would only be different if the row is selected, and you can easily check that along with the selection color.

If you are setting it yourself, you already know what the color is, no?
[/quote]
While I do set the row color, it is based on values in the cells. Since the user gets some data from a database and some cells are calculated values, there is no way to determine the row’s background color until the listbox fills the row with data. (I thought about storing the color in the RowTag but it is already being used for something else.)

Emile, I really can’t use an external storage scheme for this since there is no guarantee that the row that is one color one time will need to be the same color the next time.

somewhere (recently) I posted a similar question, about finding the best contrasting color for text on various colored backgrounds
You can override the CellTextPaint event (to do nothing), and draw the background and text your self in the CellBackGroundPaint event, this way you can use any color or combination of colors you desire.

I’d create a class of your own design that you could use for the cell or row tag. Your class could hold whatever you’re currently using row tag for as well as a background color property.

You can still have a 0 width cell or use a celltag to store this info.

What Scott said.

[quote=291280:@Dave S]somewhere (recently) I posted a similar question, about finding the best contrasting color for text on various colored backgrounds
[/quote]

I did not see that. if you did not get an answer, does this help? (It was written pre-Alpha channel)

Function ContrastingColor(InputColor as Color) as Color if (InputColor.Red*0.299 + InputColor.Green*0.587 + InputColor.Blue*0.114) > 128 then Return &c000000 else Return &cFFFFFE end if End Function

It Returns off-white because back in the day I often set White to transparent in pictures

[quote=291280:@Dave S]
You can override the CellTextPaint event (to do nothing), and draw the background and text your self in the CellBackGroundPaint event, this way you can use any color or combination of colors you desire.[/quote]
Hmmm. Thanks, Dave. That’s an approach I haven’t thought of. I’ll have to give it a try.

Dale

that is very similar (if not exactly) what I used. it checks the “gray scale” of the background and picks black or white for the text depending on how “dark” the “gray” is.