简体   繁体   中英

Move caret to start and end of line in a RichEditBox

I've a RichEditBox that I'd like to add keyboard shortcut support to enable moving to the start or the end of the line that the caret is currently on. I've already figured out shortcuts supporting going to start or end of sentence as that involved simply reviewing the text value of the content and finding the nearest period. However, I believe what I'm looking for now is more involved as it requires working through the raw content of the file, which I'm not comfortable with nor have managed to find any resources with the guidance I'm after (I've mostly found answers on detecting the EOL character type rather than moving the caret to the EOL).

If you want to move caret, we can use the RichEditBox.Document.Selection.Move method to move the insertion point forward or backward by the specified number of units.

We can set TextRangeUnit.Line to the Move method, it will move caret to start or end of line in a RichEditBox.

For example:

myRichEdit.Document.Selection.Move(TextRangeUnit.Line, 1);

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