【问题标题】:VB.NET Read current line in a text area?VB.NET 读取文本区域中的当前行?
【发布时间】:2008-11-19 22:52:16
【问题描述】:

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

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

【问题讨论】:

    标签: .net vb.net richtextbox


    【解决方案1】:

    没试过,但是:

    rtbMain.Lines(lineNumber)
    

    如果不将 Lines 属性分配给数组并访问数组元素。

    【讨论】:

      【解决方案2】:

      我想你想要

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-03-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-09
        相关资源
        最近更新 更多