I'm going to break out your questions one at a time just so it's easier to answer.
@Patrick Besong Would it be dHeight = dHeight + g.StringHeight(myText, g.width)
and that would get me the proper line height?
The original calculation I offered adds the individual line heights (they can be different depending on the characters in the line!) so that at the end of the for loop dHeight
is the total correct height for the block of myText
.
@Patrick Besong Once I do get the proper line height, how do I properly calculate by the number of lines in myText?
The example I wrote calculates the whole block of text height. I had written my example assuming numLines
was your array of strings to write. If you want each individual line, draw the string after the dHeight
is calculated for that line within the loop.
@Patrick Besong Is it just a straight dHeight * numLines
?
No, you can't assume that each line height is the same. A line's height is affected by the characters in the line. Letters like y and j extend below the baseline which is why you can't use TextAscent
for this calculation. Letters like h and i are taller than n, m, c, v. I'm not a languages expert, but I wouldn't trust that a line would always have letters that are tall.
( @Michel B is probably dying inside reading my butchering of this).
I would recommend calculating and drawing each line individually. This will make it easier for you to implement horizontal alignment later down the road. Insert a DrawString
underneath the dHeight
calculation in my example loop to get started down that path :)