Answer the question
In order to leave comments, you need to log in
How to calculate line breaks in C# Graphics?
How to determine how lines wrap when rendering multi-line text?
The text is rendered:
var _numberLines = GetNumOfLines($"{_property.Текст}", (int)(PicBoxWidth - 6), _font);
var _offcet = _font.Height * _numberLines;
g.DrawString($"{_property.Текст}", _font, Brushes.Black, new RectangleF(5, 0, PicBoxWidth - 6, _offcet), new StringFormat(StringFormatFlags.LineLimit));
private int GetNumOfLines(string multiPageString, int wrapWidth, Font fnt)
{
var sfFmt = new StringFormat(StringFormatFlags.LineLimit);
using(var g = Graphics.FromImage(New Bitmap(1, 1)))
{
var iHeight = g.MeasureString(multiPageString, fnt, wrapWidth, sfFmt).Height;
var iOneLineHeight = g.MeasureString("Z", fnt, wrapWidth, sfFmt).Height;
return (int)(iHeight / iOneLineHeight)
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question