Get the actual value of x in PaintCellText in DesktopListbox compared to g


I would like to know how to get the actual position of x inside the PaintCellText event compared to g

x is the best suited coordinate to start writing text, it’s value is by default 0 when inspecting the event through a breakpoint. It add some space from the start of the column to draw the text, but how do we get the actual value of this space between the start of the column and the start of the drawing of the text?

I tried me.ColumnAlignmentOffsetAt and CellAlignmentOffsetAt but they both returns 0

The documentation states:

The parameter g is a Graphics object that corresponds to the text drawing area of the cell identified by Row, Column. This does not necessarily correspond to the entire cell content area, for example, if you use a row picture in the cell.
The parameters x and y are the coordinates of the suggested ideal location to draw text based on the current value of ColumnAlignment or CellAlignment, as well as the cell’s font, font size, and font style.

Thank you


Don’t know if this is useful for you, but the g that is passed into he cell background paint event is for the whole cell.


Maybe this can work as a workaround comparing the graphics object of the CellBackgroundPaint event and the grahpics of the CellTextPaint event but I would need to store the values for each column. I would like to find an easier method if possible.

Thanks for the suggestion

I just found that comparing g.width with ColumnAttributesAt(column).WidthActual gives me a difference in size so I guess it’s the actual space at the start of the column.