C#에서 텍스트 편집기를 개발 중이며 줄 수를 계산하려고합니다.리치 텍스트 상자 행 수
private void updateNumberLabel()
{
Point pos = new Point(0, 0);
int firstIndex = Document.GetCharIndexFromPosition(pos);
int firstLine = Document.GetLineFromCharIndex(firstIndex);
pos.X = ClientRectangle.Width;
pos.Y = ClientRectangle.Height;
int lastIndex = Document.GetCharIndexFromPosition(pos);
int lastLine = Document.GetLineFromCharIndex(lastIndex);
int actualLine = Document.GetLineFromCharIndex(actualPos);
pos = Document.GetPositionFromCharIndex(lastIndex);
if (lastLine != actualLine)
{
numberLabel.Text = "";
for (int i = firstLine; i <= lastLine + 1; i++)
{
numberLabel.Text += i + 1 + "\n";
}
}
}
그것은 잘 작동하고 당신이 그들을 쓰는 동안 행의 수를 추가,하지만 당신은 하나를 삭제하면 삭제하거나 한 번 더 라인을 추가하는 경우에만 업데이트됩니다.
나는 그것을 즉시 만들고 싶다. 하나를 삭제하면 즉시 감소합니다.
'richTextBox.Lines.Count()'의 문제점은 무엇입니까? – derape