2008-11-19 78 views
3

我有一个文本区域和一个函数来做语法高亮。现在它读取整个RichTextBox。我将如何获得包含当前行的字符串变量?以下是我目前拥有的代码。VB.NET读取文本区域中的当前行吗?

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 

回答

2

没有尝试过但:

rtbMain.Lines(lineNumber) 

如果不分配Lines属性到一个数组并访问数组元素。

1

我想你想

rtbMain.Lines(rtbMain.GetLineFromCharIndex(rtbMain.SelectionStart))