Drawstring Text width

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
 
H

Herfried K. Wagner [MVP]

* "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()
///
 
H

Herfried K. Wagner [MVP]

* "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.
 

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

Top