DesktopListBox.PaintCellText changes text height?

Wondering if anyone can confirm this or if I’m going crazy.

Got a listbox with a bunch of words in it. It displays correctly:


But if I add a PaintCellText event to change the color of the text, the descenders seemingly get cut off by a pixel (notice the bottom of the g’s and y’s):


Here’s the code I’m using:

Function PaintCellText(g as Graphics, row as Integer, column as Integer, x as Integer, y as Integer) Handles PaintCellText as Boolean
  Var cellText As String = Me.CellTextAt(row, column)
  g.DrawingColor = Color.RGB(179, 102, 255) ' #B366F
  g.DrawText(cellText, x, y)
  Return True
End Function

Sample project here.

Has it always behaved this way?

Interestingly enough, if I change the DrawText line to:

g.DrawText(cellText, x, y-1)

it visibly moves up a pixel (the descenders are fine but now the ascenders get cut off)

If I change the line to:
g.DrawText(cellText, x, y-0.5)

It draws correctly!

I wonder if this has something to do with a rounding error in display scaling. My current display is at 150% scaling.

Yeah that could be the issue. Do something like ceil(y) and see if that helps.

1 Like

Try commenting out the first line and the third line, then Return False

Something @Tim_Parnell said in another thread recently.

1 Like

That is certainly the issue. I wonder why the x and y parameters in PaintCellText are integers although Graphics.DrawText takes doubles.

Two solutions:

  1. If you only want to change the text color, do this:
  1. If you want some fancy drawing try this
    g.drawtext(cellText, x, (g.height-g.textheight)/2+g.font.ascent)

Thanks everyone,

Only changing the DrawingColor and Returning False does the trick for this one. Didn’t know that would work!

Can’t seem to replicate the issue on a VM, even after changing the scaling, it only happens on a native Windows machine.