VB.NET ¿Leer la línea actual en un área de texto?
-
08-07-2019 - |
Pregunta
Tengo un área de texto y una función para resaltar la sintaxis. En este momento lee todo el RichTextBox. ¿Cómo obtendría una variable de cadena que contiene la línea actual? A continuación se muestra el código que tengo actualmente.
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
Solución
No lo probé pero:
rtbMain.Lines(lineNumber)
si no asigna la propiedad Líneas a una matriz y accede al elemento de matriz.
Otros consejos
Creo que quieres
rtbMain.Lines(rtbMain.GetLineFromCharIndex(rtbMain.SelectionStart))
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow