简体   繁体   中英

Set caret to start of line in WPF RichTextBox

I've got a RichTextBox containing lines of text (each line a paragraph), and I have a line number that represents an error. I want to set the caret to be at the start of that line. How?

I haven't got a working installation of C# on my machine at the moment, but from looking at the docs it seems you should be able to first locate the paragraph you want (probably by enumerating through them, there does not seem to be an index function) in yourFlowDocument.Blocks and then:

TextPointer paragraphStart = paragraph.ElementStart;
richTextBox.CaretPosition = paragraphStart;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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