I don’t know if you ever get the perfect measurement, but it’s close:
private int GetTextHeight(TextBox tBox) {
return TextRenderer.MeasureText(tBox.Text, tBox.Font, tBox.ClientSize,
TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl).Height;
}
TextBox can be dumb. When you turn on the multi-line line, if you click on the character that calls the word word-wrap, clicking on the backspace will not produce "un-word-wrap" unless I resize the TextBox. It was on Win7-64. I do not think the TextBox control has always done this.
source
share