我正在寻找最佳的方法来对RichTextBox中的行进行排序,目前我正在使用以下代码:
public void SortLines(object sender, EventArgs e)
{
TextPointer pStart = TextInput.Document.ContentStart;
TextPointer pEnd = TextInput.Document.ContentEnd;
TextRange text = new TextRange(pStart, pEnd);
string[] lines = text.Text.Split('\n');
Array.Sort(lines);
text.Text = String.Join(String.Empty, lines);
}
有没有最好的方法来实现这个?
当我调用它时,光标会被放置到第一行的RichTextBox中,我该如何将其放回到之前的位置? 我试过设置pStart/pEnd和CaretPosition,但这些属性是只读的。
希望我的意思清楚了。非常感谢您提前的帮助。