the height of a string

  • Thread starter Thread starter ThunderMusic
  • Start date Start date
T

ThunderMusic

Hi,
is there a way to know the height of a string printed in a rectangle? I
mean. I would like to create a rectangle high enough to contain all the
string but I don't want to increase the width so I have to determine the
height the string will have when printed in order to create a high enough
rectangle.

Is there an easy way to know the height of the rectangle I must create in
order to contain all my string?

thanks

ThunderMusic
 
I assume you are using wordwrap. The following will give you the height of
the rectangle you need as well as the number of lines where myWidth is the
width of the rectangle (integer) you want and myAlign is the StringFormat you
want to use..

Dim sz As SizeF = gph.MeasureString(s, myFont, myWidth, myAlign)
' sz will be the size of the rectangle needed where the width is myWidth

'Get the number of lines
Dim nlines As Single = (sz.Height) / myFont.Height
 
it worked great, thanks!!

Dennis said:
I assume you are using wordwrap. The following will give you the height of
the rectangle you need as well as the number of lines where myWidth is the
width of the rectangle (integer) you want and myAlign is the StringFormat you
want to use..

Dim sz As SizeF = gph.MeasureString(s, myFont, myWidth, myAlign)
' sz will be the size of the rectangle needed where the width is myWidth

'Get the number of lines
Dim nlines As Single = (sz.Height) / myFont.Height
 

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