Skip to content

How to select specific line in richtextbox in WPF? #7812

Answered by miloush
VahidEra asked this question in Q&A
Discussion options

You must be logged in to vote

https://learn.microsoft.com/en-us/dotnet/api/system.windows.documents.textpointer would be a useful reading to you. It has a simple example of how to find a string inside a text. You can call it in your demo like this:

    Public Sub SelectLine(ByVal text As String)
        Dim start As TextPointer = FindWordFromPosition(rtb.Document.ContentStart, text)
        Dim [end] As TextPointer = start.GetPositionAtOffset(text.Length)
    ...

But as I said, depending on where the text comes from and what users can do in the text box, this will break easily.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@VahidEra
Comment options

@miloush
Comment options

@miloush
Comment options

@miloush
Comment options

Answer selected by VahidEra
@VahidEra
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants