VB.NET 读取文本区域中的当前行?
我有一个文本区域和一个在其上进行语法突出显示的函数。 现在它读取整个 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
I have a text area and a function to do syntax highlighting on it. Right now it reads the entire RichTextBox. How would I get a string variable containing the current line? Below is the code i currently have.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有尝试过,但是:
如果没有将 Lines 属性分配给数组并访问数组元素。
Not tried it but:
if not assign the Lines property to an array and access the array element.
我想你想要
I think you want