使用GetCharIndexFromPosition

时间:2016-09-30 14:55:40

标签: c# .net winforms richtextbox

所以我有一个富文本框,我试图得到最后一行可见行中第一个字符的索引,但我有一个问题。

我正在尝试使用以下方法检索索引:

int lastVisibleCharIndex= messageEditorRtb.GetCharIndexFromPosition(new Point(0, messageEditorRtb.Height));
int lastVisibleLine= messageEditorRtb.GetLineFromCharIndex(lastVisibleCharIndex);
if (lastVisibleLine>= messageEditorRtb.Lines.Length) return;

在我尝试检索富文本框中最后两行的索引之前,这是有效的。无论最后一行是最后一行还是最后一行,我总是得到相同的lastVisibleCharIndex值,我不知道为什么会这样。有没有人建议如何在富文本框中获取最后一行?

我收录了我的问题图片,以帮助解释它。

当运行下面第一张图片的代码时,返回索引42。 enter image description here

当运行下面图像的代码时,也返回索引42。 enter image description here

最后一行应返回大于倒数第二行的索引。有人能看出为什么会这样吗?

感谢。

0 个答案:

没有答案