MeasureText
和MeasureString
功能具有重載接受textarea width, height
和TextFormatFlags(TextBoxControl, WordBreak e.t.c)
您可以比較text size
與RichTextBoxControl size
Size stringSize = new Size();
string text = SomeText();
stringSize = TextRenderer.MeasureText(text, richTextBox1.Font, new Size(richTextBox1.Size.Width, richTextBox1.Size.Height), TextFormatFlags.WordBreak);
string r = string.Format("RTB Width : {0}\r\n", richTextBox1.Size.Width);
r += string.Format("RTB Height : {0}\r\n", richTextBox1.Size.Height);
r += string.Format("TEXT Width : {0}\r\n", stringSize.Width);
r += string.Format("TEXT Height : {0}", stringSize.Height);
MessageBox.Show(r);
爲什麼投票結束? – camino
將WordWrap設置爲true時,您不應該看到水平滾動條。 – LarsTech
@LarsTech我們無法控制垂直滾動條,對吧? – camino