Salve
Per cortesia potete aiutarmi a risolvere un problema.
Non riesco a centrare una stringa all’interno di un rettangolo disegnato in una canvas.
// DICHIARA IL TIPO DI FONT LE DIMENSIONI E SE ESSO DEVE ESSERE DISEGNATO IN GRASSETTO O NO
dim p as picture = new picture(1,1,32)
p.Graphics.textfont= "system"
p.Graphics.textsize=40
p.Graphics.TextUnit=FontUnits.pixel
Dim Altezzastringa as integer = p.Graphics.StringHeight(ColoredButton(i).getcaption(), 100000)
ButtonSize = Altezzastringa + 15
// DISEGNA LA PANEL DI LUNGHEZZA CALCOLATA PRECEDENTEMENTE NELLA VARIABILE ( LunghezzaTasto )
Dim Tasto as New FigureShape
Tasto.AddLine 0 , 0, me.width, 0
Tasto.AddLine me.width , ButtonSize, 0 , ButtonSize
Tasto.BorderWidth = 0
Tasto.Border = 100 // opaque border
// SE IL TASTO SELEZIONATO ALLORA...
if i = SelectedButton then
// DISEGNA IL TASTO CON IL COLORE BIANCO PERCHE SELEZIONATO
Tasto.FillColor = Rgb(255,255,255)
g.DrawObject Tasto, 0 ,47 + (ButtonSize *I)
// DISEGNA LA LINEA DEL BORDO ORIZZONTALE
g.ForeColor = ColoreBordoTasto
g.DrawLine(0, 47 + (ButtonSize *I), me.width, 47 + (ButtonSize *I))
g.textfont= "system"
g.textsize=40
g.TextUnit=FontUnits.pixel
g.ForeColor = ColoreFontTasto
g.DrawString(ColoredButton(i).GetCaption(), 20 , (((ButtonSize / 2 )- (Altezzastringa / 2) ) + 47 + ( ButtonSize* i) + Altezzastringa , me.width - 40, true))