title: Cursor position inside a RichTextBox in WPF
body: <p>I am developing a small WPF application, which has multiple tabs in it. I have a status bar in the bottom; the requirement is to show linenumber and column of the cursor. So when the user changes the cursor position, linenumber and column has to get updated automatically. Here is the code where I add RichTextBox; the code which calculates the linenumber and column is in the KeyDown event handler, but this event never gets called. Which event should I handle to get the cursor linenumber and column?</p>
  
  <pre><code>private void AddTabitem(string filePath, mode fileMode)
  {
      if (fileMode == mode.openFile)
      {
          if (File.Exists(filePath))
          {
              RichTextBox mcRTB = new RichTextBox();
              mcRTB.KeyDown += new KeyEventHandler(LineNumber);
  //rest of the code goes here
          }
      }
  }
  mcRTB.KeyDown += new KeyEventHandler(LineNumber);
  
  private void LineNumber(object sender, KeyEventArgs e)
  {          
      TextPointer tp1 = rtbList[EditorTabcontrol.SelectedIndex].Selection.Start.GetLineStartPosition(0);
      TextPointer tp2 = rtbList[EditorTabcontrol.SelectedIndex].Selection.Start;
  
      int column = tp1.GetOffsetToPosition(tp2);
  
      int someBigNumber = int.MaxValue;
      int lineMoved, currentLineNumber;
      rtbList[EditorTabcontrol.SelectedIndex].Selection.Start.GetLineStartPosition(-someBigNumber, out lineMoved);
      currentLineNumber = -lineMoved;
      string LineColumnLabel;
  
      //LineColumnLabel.Content = "Line: " + currentLineNumber.ToString() + " Column: " + column.ToString();
      LineColumnLabel = "Line: " + currentLineNumber.ToString() + " Column: " + column.ToString();        
  }
  </code></pre>