Sunday, December 13, 2009

VB.Net Draw String Center of Point location

Private Sub DrawStringCenterOfPoint(ByRef gr As Graphics, _
ByVal txt As String, ByVal txtfont As Font, _
ByVal txtcolor As Brush, ByVal location As PointF)

' Mark the center for debugging
Dim x as Single = location.X
Dim y as Single = location.Y
gr.DrawLine(New Pen(Color.Red, 2), x - 10, y, x + 10, y)

' Make a StringFormat object that centers
Dim sf As New StringFormat
sf.LineAlignment = StringAlignment.Center
sf.Alignment = StringAlignment.Center

' Draw the text.
Dim StringSize As New SizeF
StringSize = gr.MeasureString(txt, txtfont)

gr.DrawString(txt, txtfont, txtcolor, x, y, sf)
sf.Dispose()

End Sub

No comments:

Post a Comment