title: Richtextbox lines count
body: <p>I'm developing a text editor in C#, and I'm trying to make a line count.</p>
  
  <pre><code>    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 &lt;= lastLine + 1; i++)
              {
                  numberLabel.Text += i + 1 + "\n";
              }
          }
      }
  </code></pre>
  
  <p>It works fine and adds the number of lines while you write them, but if you delete one, it will only update if you delete or add one more line.</p>
  
  <p>I want make it instantaneous. If you delete one, the count shall be decreased instantaneously.</p>