You’ll have to use PaintCellText and set colors that stand out against the backgrounds.
Be sure to include Return True or the text will be doubled in listbox rows.
Select Case column
Case 1
Var mytext As String = Me.CellTagAt(row, 1)
Var lines() As String = mytext.Split(EndOfLine)
Var myColor As Color
mycolor = If(row Mod 2 = 0, &c13448300, &cFF6E0000)
Var l As Integer = lines.Count
g.ForeColor = myColor
g.DrawText(mytext, 0, (g.TextHeight))
End Select
Return True
You can use a ColorGroup to define a colour for light mode and another for dark mode.
Var OddRow as New ColorGroup( &cFF6E0000, &c00CC0000 ) // fist colour for light, second for dark
Var EvenRow as New ColorGroup( &c13448300, &c11223300 )
...
mycolor = If(row Mod 2 = 0, EvenRow, OddRow)
Wouldn’t that draw the text outside of the graphics area?
The x,y co-ordinates are the baseline for drawtext…
If you aren’t seeing any text, try
Handles PaintCellText as Boolean
if IsDarkMode Then
g.DrawingColor = RGB(255,0,0)
//these colors are silly, and purely to show which mode is detected
else
g.DrawingColor = RGB(0,0,255)
//these colors are silly, and purely to show which mode is detected
end if
g.Bold = True
g.DrawText Me.CellTextAt(0),0,g.height * 0.9 // draw just off the bottom
//better would be to center the words by adjusting for the font height
// versus the g.height
return true // now that we did the letters, dont let the system also draw them
End Function
If all you want to do is change the text color, dont draw the text:
Handles PaintCellText as Boolean
if IsDarkMode Then
g.DrawingColor = RGB(255,0,0)
//these colors are silly, and purely to show which mode is detected
else
g.DrawingColor = RGB(0,0,255)
//these colors are silly, and purely to show which mode is detected
end if
g.Bold = True
return false // let the system draw the words
End Function
So you see text because after your drawing, system will draw the text with its defaults again. As Jeff pointed out, you should usually use the x and y parameters from the PaintCellText event, not (0,0). And return true; otherwise system will still draw on its own afterwards.
Just your darkmode listbox isn’t dark mode. You define the text color as black, but it would be more recommendable to use PaintCellBackground too and switch the too bright colors of the cells.
My answer was in response to you saying you did not return true in PaintCellText because nothing would be displayed.
In dark mode, the system is painting text as white.
That’s correct.
You can’t see it easily because YOU are changing the background (which would have been black) , to yellow and blue.
Since you are changing the background, it will never be black, and the text should not be allowed to go white.
Your text needs to be black, whether it is dark mode or not.
So your PaintCellText needs to be this and only this:
Handles PaintCellText as Boolean
g.DrawingColor = RGB(0,0,0)
g.Bold = True
g.DrawText Me.CellTextAt(0),0,g.height * 0.9
return true //do not let the system also draw the letters
End Function
Looks like you misunderstanding things, the system is drawing with white text but because you changed the rows to light blue/yellow, you can’t see the white text.
Maybe zooming in you can see the text?
You have several options:
a) remove the light blue/yellow colors and let the default listbox adjust to light/dark mode
b) handle the text color yourself for dark mode
c) use different colors for your light blue/yellow when in Dark Mode knowing that the text will be Black in Light mode and White in Dark Mode
d) use ColorGroup definitions to handle c)
As Alberto wrote, your observation is wrong. Text is always displayed, but because of your rows being colored way too bright, there is not enough contrast to white text until the row is repainted with the (darker) selection color as background.
I don’t see any sense in using DarkMode while text background is defined for white mode compatibility. Either switch off DM or use different background cell colors which contrast with white text.