Measure the height of the line

My program draws multiline text in a field in a PrintDocument using the PrintPage event. The width is set, but the height should increase depending on the size of the text.

int BoxHeight = (int)e.Graphics.MeasureString(StringToDraw, FontToUse, BoxWidth).Height;

This returns basically double the height they seek most of the time, but not always. The e object is the System.Drawing.Printing.PrintPageEventArgs passed to the PrintDocument.PrintPage event. I want the box to fit text tightly, without wasting dead trees to print white blank spaces.

I was looking for solutions, but maybe this is something that I did not understand, because I could not get them to work for me.

+3
source share
1 answer

. BoxWidth , . .

+1