RichTextBox中的MeasureString问题 [英] MeasureString in RichTextBox Problem
问题描述
当垂直的scroolbar变得可见时,我需要得到rtb的最后一行。
WordWrap是真的
我已经有一个方法告诉我什么时候scroolbar变得可见。
我测量了最后一行的字符串并将其与宽度相比>更大的一切都在最后一行。我的问题是,当它到达中间位置时,它说它已经到了最后。
继承我的代码:
I need to get the last line of a rtb when the vertical scroolbar becomes visible.
WordWrap is true
I allready have a methode which tells me when the scroolbar becomes visible.
I measured the string of the last line and compared it to the width > everything which is bigger is in the last line. My Problem is, that when it reaches about the middle, it says it allready reached the end.
Heres my code:
float sum = 0;
int zeichen = 0;
Graphics g = rtb.CreateGraphics();
g.PageUnit = GraphicsUnit.Pixel;
for (int i = 0; i < rtb.Lines[rtb.Lines.Length - 1].Length && sum < rtb.Width; i++)
{
zeichen = i;
rtb.Select(rtb.GetFirstCharIndexFromLine(rtb.Lines.Length - 1) + i, 1);
sum = sum + g.MeasureString(rtb.SelectedText, rtb.SelectionFont).Width;
}
string s = rtb.Text.Substring(zeichen);
rtb.Text = rtb.Text.Substring(0, zeichen);
SelectionFont = new System.Drawing.Font(Agency FB,10)
rtb.width = 605
谢谢:)
SelectionFont = new System.Drawing.Font("Agency FB", 10)
rtb.width = 605
Thanks :)
推荐答案
这篇关于RichTextBox中的MeasureString问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!