I am developing a small WPF application that has several tabs. I have a status bar below; the requirement is to show the linen number and the cursor column. Therefore, when the user changes the cursor position, the name and column should be updated automatically. Here is the code where I add RichTextBox; the code that calculates the row number and column is in the KeyDown event handler, but this event is never called. What event should I process to get the linenumber cursor and column?
private void AddTabitem(string filePath, mode fileMode)
{
if (fileMode == mode.openFile)
{
if (File.Exists(filePath))
{
RichTextBox mcRTB = new RichTextBox();
mcRTB.KeyDown += new KeyEventHandler(LineNumber);
}
}
}
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 = "Line: " + currentLineNumber.ToString() + " Column: " + column.ToString();
}
source
share