私はテキストエディタを作成していますが、これらの機能を実行するためのより高速で信頼性の高い方法があるかどうか疑問に思いました。私がここに書いたことは、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();
}
}