Question

J'ai une zone de texte et une fonction pour mettre en évidence la syntaxe. À l'heure actuelle, il lit l'intégralité de RichTextBox. Comment pourrais-je obtenir une variable de chaîne contenant la ligne actuelle? Vous trouverez ci-dessous le code que j'ai actuellement.

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
Était-ce utile?

La solution

Non essayé mais:

rtbMain.Lines(lineNumber)

si ce n'est pas le cas, assignez la propriété Lines à un tableau et accédez à l'élément de tableau.

Autres conseils

Je pense que vous voulez

rtbMain.Lines(rtbMain.GetLineFromCharIndex(rtbMain.SelectionStart))
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top