【发布时间】:2012-03-18 09:52:16
【问题描述】:
我正在使用 C#、Windows 窗体应用程序,并且在获取包含大量文本的 RichTextBox 的滚动位置时遇到问题。
我正在使用此代码:
public class POINT
{
public int x;
public int y;
public POINT()
{
}
public POINT(int x, int y)
{
this.x = x;
this.y = y;
}
}
SendMessage(this.Handle, EM_GETSCROLLPOS, 0, res)
但是,当控件包含大量文本时,导致 y 偏移不正确,因为 Y 的高 16 位始终为 0。
有没有办法让滚动位置大于 16 位?
【问题讨论】:
-
看看at this
-
使用 GetCharIndexFromPosition() 代替。 GetLineFromCharIndex() 转换为行号。
-
感谢重播。 @HansPassant - 我成功获得了 GetPositionFromCharIndex 的位置。即,该函数返回相对于控件视图的位置,因此 GetPositionFromCharIndex(0) 返回控件的准确滚动位置。
标签: c# richtextbox scroll-position