Drawstring Text width

  • Thread starter Thread starter Cliff Lane
  • Start date Start date
C

Cliff Lane

I am just getting into the area of printing and I am trying to determine the
maximum drawing width that a text field of 25 characters will take up so I
can right align the next field. Is there something comparable to the
textwidth method of vb 6 that will give me this information?

Thanks
 
* "Cliff Lane said:
I am just getting into the area of printing and I am trying to determine the
maximum drawing width that a text field of 25 characters will take up so I
can right align the next field. Is there something comparable to the
textwidth method of vb 6 that will give me this information?

'Graphics.MeasureString':

<URL:http://msdn.microsoft.com/library/e...temdrawinggraphicsclassmeasurestringtopic.asp>

\\\
Dim g As Graphics = Label1.CreateGraphics()
Dim s As SizeF = _
g.MeasureString(Label1.Text, Label1.Font, Label1.Width, StringFormat.GenericTypographic)
g.Dispose()
///
 
* "Cliff Lane said:
I am just getting into the area of printing and I am trying to determine the
maximum drawing width that a text field of 25 characters will take up so I
can right align the next field. Is there something comparable to the
textwidth method of vb 6 that will give me this information?

Have a look at 'e.Graphics' in the 'PrintDocument''s 'PrintPage' event
handler. You can use 'Graphics' object's 'MeasureString' method there
to get the size of the text, and you can specify the alignment in the
'DrawString' method.
 
Back
Top