简体   繁体   English

WPF RichTextBox-获取当前行

[英]WPF RichTextBox - get current line

How to get the current line (and remove) in WPF's RichTextBox? 如何在WPF的RichTextBox中获取当前行(并删除)? There is no usefull functions such as RichTextBox.GetLineFromCharIndex() in WinForms. WinForms中没有有用的函数,例如RichTextBox.GetLineFromCharIndex()

Thanks in advance. 提前致谢。
CH CH

You can get a paragraph by calling Paragraph para=CaretPosition.Paragraph; 您可以通过调用Paragraph para=CaretPosition.Paragraph;来获取段落Paragraph para=CaretPosition.Paragraph;

If you want to remove this paragraph, use Document.Blocks.Remove(para) . 如果要删除此段落,请使用Document.Blocks.Remove(para) if you want to remove the line in which the Caret is, you should find two TextPointer s: The one at the begining of the line and the one at the end. 如果你想删除Caret所在的行,你应该找到两个TextPointerTextPointer ,一行在末尾。 Call these two tp1 and tp2 . 将这两个tp2 tp1tp2 You can remove the line by 您可以删除该行

TextRange tr=new textRange(tp1,tp2);
tr.Text=""; 

If I've understood correctly, let me know to explain how you can get the two TextPointers 如果我理解正确,请告诉我解释如何获取两个TextPointers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM