问题描述
我首先想到的是它会是这样的:
My first thought was it would be something like this:
int height = textbox.lines.length * lineheight;
但它只是计算\xd\\\
和线条都可以被包装。我可以显示的行或文本框的实际高度数时,一切是可见的(文本的高度内)?
But it just counts "\xd\n" and lines can be wrapped. Can i get the number of displayed lines or actual height of textbox when everything is visible(the height of text inside)?
推荐答案
我不知道你永远不会得到一个完美的测量,但这种靠拢:
I don't know if you will ever get a perfect measurement, but this gets close:
private int GetTextHeight(TextBox tBox) {
return TextRenderer.MeasureText(tBox.Text, tBox.Font, tBox.ClientSize,
TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl).Height;
}
文本框可以是愚蠢的。多线开启,如果按下导致该单词自动换行,一个角色打退格不会导致其非自动换行,除非我调整文本框。这是在一个Win7-64。我不的认为的TextBox控件总是这样做。
The TextBox can be goofy. With multi-line turned on, if you press a character that causes the word to word-wrap, hitting backspace does not cause it to "un-word-wrap" unless I resize the TextBox. This was on a Win7-64. I don't think the TextBox control always did that.
这篇关于如何获得文本框真实的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!