Listbox Centering Problem

Can someone help me with the centering of text in a listbox cell.

I am not bad on math but for some reason I cannot get the text to center.

Here is the button project I am working on. Button Project

x=(g.width-g.stringwidth(s))/2
y=((g.height-g.textheight)/2)+g.textascent
g.drawstring s,x,y

where “s” is the string of the text you wish to display

or add an event to your listbox

Function CellTextPaint(g As Graphics, row As Integer, column As Integer, x as Integer, y as Integer) As Boolean if row>-1 and row<me.ListCount then g.DrawString(me.cell(row,column),g.Width/2-g.StringWidth(me.cell(row,column))/2,y) Return true end if End Function

Thanks you guys. As both worked in different ways I had to use Jim’s as the button text will be unknown.

The user will be able to add buttons or delete them so I’ll be pulling the button information from a preferences
file and add the buttons with text then.

Again thanks guys.