DrawString

  • Thread starter Thread starter Rlrcstr
  • Start date Start date
R

Rlrcstr

Using Graphics.DrawString, is it possible to specify that the text is draw
centerd horizontally and/or vertically in the specified layout rectangle?
Thanks.

Jerry
 
Nevermind... Figured it out.

Dim s As New StringFormat

s.Alignment = StringAlignment.Center

s.LineAlignment = StringAlignment.Center
 
Hi,

Use the drawstring that accepts a string format.

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Dim sf As New StringFormat

Dim strOut As String = "Hello World"

With sf

..LineAlignment = StringAlignment.Center ' center vertically

..Alignment = StringAlignment.Center 'center horizontally

End With

e.Graphics.DrawString(strOut, Me.Font, Brushes.Black, _

RectangleF.op_Implicit(Me.ClientRectangle), sf)

End Sub



http://msdn.microsoft.com/library/d...ystemdrawinggraphicsclassdrawstringtopic3.asp

http://msdn.microsoft.com/library/d...temdrawingstringformatclassalignmenttopic.asp

http://msdn.microsoft.com/library/d...rawingstringformatclasslinealignmenttopic.asp

Ken
--------------------
Using Graphics.DrawString, is it possible to specify that the text is draw
centerd horizontally and/or vertically in the specified layout rectangle?
Thanks.

Jerry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top