Private Sub CenterTextAt(ByVal gr As Graphics, ByVal txt As _
String, ByVal x As Single, ByVal y As Single)
' Mark the center for debugging.
gr.DrawLine(Pens.Red, x - 10, y, x + 10, y)
gr.DrawLine(Pens.Red, x, y - 10, x, y + 10)
' Make a StringFormat object that centers.
Dim sf As New StringFormat
sf.LineAlignment = StringAlignment.Center
sf.Alignment = StringAlignment.Center
' Draw the text.
gr.DrawString(txt, Me.Font, Brushes.Black, x, y, sf)
sf.Dispose()
End Sub
|