Listbox CellTextPaint position

I noticed that in the CellTextPaint event using

case "0" g.ForeColor = &c83C14000 g.FillRect(0,0,5,g.Height) case "1" g.ForeColor = &cFFD15C00 g.FillRect(0,0,5,g.Height)

does not paint exactly to the left of the listbox, leaving a gap of some pixels.

Is it possible to paint exactly to the left?

Look into Listbox.ColumnAlignmentOffset and/or Listbox.CellAlignmentOffset

Not tested but may be workable

case "0" g.ForeColor = &c83C14000 g.FillRect(0,0,5,g.Height) case "1" g.ForeColor = &cFFD15C00 g.FillRect(0,0,5,g.Height)
This code should be in the CellBackgroundPaint.

Echoing what Eli wrote; if you’re wanting this sort of thing you need to be doing it in CellBackgroundPaint. Listboxes have an offset from the left edge; I don’t think that either of the AlignmentOffsets will help. I spent a lot of time trying to work out how to do this in CellTextPaint before giving up and putting it in CellBackgroundPaint.

Doesn’t work indeed. I’ll try to paint this in CellBackgroundPaint.

Thanks!

The width used in the CellTextPaint event is a little less than the width of the cell. That is to offset the text a tiny bit from the left edge of the cell. If you want to color the background use the CellBackground paint event where it will fill the entire cell with the color and be sure to return true at the end so that the normal background coloring does not take place.