我正在开发一款小型WPF应用程序,其中包含多个选项卡。 底部有一个状态栏; 要求显示光标的行号和列号。 因此,当用户更改光标位置时,行号和列号必须自动更新。 这是我添加RichTextBox的代码; 计算行号和列号的代码位于KeyDown事件处理程序中,但此事件从未被调用。 我应该处理哪个事件来获取光标的行号和列号?
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();
}