1

This may be an easy answer but it's just not coming to me at the moment. My program opens a file and the file does contain comments, I want to make all the text after "//" in a line green.

What I am trying to do is something like this: (It's exactly the same way for commenting in VB.Net but with ')

If rtb.contains("//") Then
   'make the text after '//' green
End If
dovid
  • 6,354
  • 3
  • 33
  • 73
  • You mean how do you do this in a textbox control? If you're using windows forms then the below link will give you the answer. http://stackoverflow.com/questions/2527700/change-color-of-text-within-a-winforms-richtextbox – ShadowLiberal Jan 06 '14 at 19:02
  • @ShadowLiberal eh not quite. You know how if you type "//this is now a comment" in c# and the text after the // turns green (including the //), that's what I am trying to do for my program. – user3166518 Jan 06 '14 at 19:09

2 Answers2

0

Assuming existing text, you can run through the Lines array to inspect the text:

For i As Integer = 0 To RichTextBox1.Lines.Length - 1
  Dim s As String = RichTextBox1.Lines(i)
  Dim index As Integer = s.IndexOf("//")
  If index > -1 Then
    Dim length As Integer = s.Length - index
    index += RichTextBox1.GetFirstCharIndexFromLine(i)
    RichTextBox1.Select(index, length)
    RichTextBox1.SelectionColor = Color.Green
  End If
Next
RichTextBox1.Select(0, 0)
LarsTech
  • 80,625
  • 14
  • 153
  • 225
0

Are you using a Textbox? If so, you need to use a RichTextbox to do what you want. Like this:

enter image description here

'Sets the selectionstart character 'Sets the number of selected characters after the selecionstart character 'Sets the selection color

Edit: Oh you wanted after the "\\" characters, misread, use the @LarsTech answer i think.

SomeNickName
  • 511
  • 6
  • 32