我正在制作一个文本编辑器,我想知道是否有更快/更可靠的方法来执行这些功能。我在这里写的是我认为我能做的最好的并且可能能做到的,除了我有一种感觉 FirstVisibleLine 和 LineCount 已经完成但 VisibleLines 可以更快地返回......?
VisibleLines 应该返回在文本区域中可见的文本行数。FirstVisibleLine 应该返回文本区域中的第一条可见行 LineCount 应该返回文本区域中的行数
private int VisibleLines()
{
int topIndex = this.GetCharIndexFromPosition(new Point(0, 0));
int bottomIndex = this.GetCharIndexFromPosition(new Point(0, this.Height - 1));
int topLine = this.GetLineFromCharIndex(topIndex);
int bottomLine = this.GetLineFromCharIndex(bottomIndex);
return bottomLine - topLine;
}
private int FirstVisibleLine()
{
return this.GetLineFromCharIndex(this.GetCharIndexFromPosition(new Point(0,0)));
}
public int LineCount
{
get
{
Message msg = Message.Create(this.Handle, EM_VISIBLELINES, IntPtr.Zero, IntPtr.Zero);
base.DefWndProc(ref msg);
return msg.Result.ToInt32();
}
}