g.DrawString not centered?

Hi all,

I have a listbox (width 90) without scrollbars on a floating window (width 90) without scrollbars.

In the CellTextPaint event I draw an icon (width 64) and some text (stored in a dynamic constant)

[code]Function CellTextPaint(g As Graphics, row As Integer, column As Integer, x as Integer, y as Integer) As Boolean
g.TextFont = “System”
g.TextSize = 10
g.Bold = True
g.Italic = True
g.ForeColor = &cBBBBBB

select case row

case 0

g.DrawPicture( NewDigest_64x64, 13, 5, 64, 64 )   // (90-64) / 2 = 13
g.DrawString( kTB_NewDigest, ( me.Width - g.StringWidth( kTB_NewDigest ) )/2, 80 )

case 1

g.DrawPicture( OpenDigest_64x64, 13, 5, 64, 64 )   // (90-64) / 2 = 13
g.DrawString( kTB_OpenDigest, (me.Width - g.StringWidth(kTB_OpenDigest) )/2, 80 )

// etc

end Select

End Function[/code]

However neither the picture nor the text are drawn centred.

Any idea where I am going wrong?

Tried it in both RS 2012R2.1 and Xojo 2014R2 on MacOS X 10.9.4

try usin g .Width and drawing in CellBackgroundPaint.

Thanks Karen, that works (even without changing me to g).

But why would the text center in the CellBackgroundPaint event but not the CellTextPaint event? I had even tried to disable all the picture drawing code but it still wouldn’t center.

CellTextPaint leaves a margin…Also I assume in this case that it is a hierarchical Listbox which leaves room for the widget in the first row?

  • Karen

Not a hierarchical one. Just a floating palette to choose different options from. I had a toolbar before but wanted a vertical arrangement.

BTW … Salad dressing (oil) for a hydrophobicity icon… I don’t think I would have though of that! :wink:

  • Karen

Yeah, that was a difficult one. I had a ying/yang icon but that didn’t really fit, but olive oil did :slight_smile: