VB.NET Read current line in text area?

I have a text area and a function for syntax highlighting. He is currently reading the entire RichTextBox. How to get a string variable containing the current string? Below is the code that I have.

Private Sub HighLight()
    Dim rm As System.Text.RegularExpressions.MatchCollection
    Dim m As System.Text.RegularExpressions.Match
    Dim x As Integer ''lets remember where the text courser was before we mess with it

    For Each pass In FrmColors.lb1.Items
        x = rtbMain.SelectionStart
        rm = System.Text.RegularExpressions.Regex.Matches(LCase(rtbMain.Text), LCase(pass))
        For Each m In rm
            rtbMain.Select(m.Index, m.Length)
            rtbMain.SelectionColor = Color.Blue
        Next
        rtbMain.Select(x, 0)
        rtbMain.SelectionColor = Color.Black
    Next
End Sub
+3
source share
2 answers

Did not try, but:

rtbMain.Lines(lineNumber)

unless you assign the Lines property to the array and access the element of the array.

+2
source

I think you want

rtbMain.Lines(rtbMain.GetLineFromCharIndex(rtbMain.SelectionStart))
+1
source

All Articles