VB.NET Leggi la riga corrente in un'area di testo?
-
08-07-2019 - |
Domanda
Ho un'area di testo e una funzione per evidenziare la sintassi. In questo momento legge l'intero RichTextBox. Come otterrei una variabile stringa contenente la riga corrente? Di seguito è riportato il codice che ho attualmente.
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
Soluzione
Non provato ma:
rtbMain.Lines(lineNumber)
in caso contrario assegnare la proprietà Lines a un array e accedere all'elemento array.
Altri suggerimenti
Penso che tu voglia
rtbMain.Lines(rtbMain.GetLineFromCharIndex(rtbMain.SelectionStart))
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow