Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 WPF 中获取当前行(并删除)RichTextBox?
RichTextBox
Winforms 具有RichTextBox.GetLineFromCharIndex()WPF 中没有的功能。
RichTextBox.GetLineFromCharIndex()
您可以通过调用获得一个段落Paragraph para=CaretPosition.Paragraph;
Paragraph para=CaretPosition.Paragraph;
如果要删除此段落,请使用Document.Blocks.Remove(para). 如果你想删除插入符号所在的行,你应该找到两个TextPointers:一个在行首,一个在行尾。调用这两个tp1和tp2。您可以通过以下方式删除该行
Document.Blocks.Remove(para)
TextPointer
tp1
tp2
TextRange tr=new textRange(tp1,tp2); tr.Text="";
如果我理解正确,请告诉我如何获得这两个 TextPointers