Results 1 to 4 of 4

Thread: [RESOLVED] [2008] Rich text box help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Resolved [RESOLVED] [2008] Rich text box help

    I need to change the color of every line starting with a "#" to green. How can I do this. I have searched around the forums and i have found nothing. Any help would be great thanks.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Rich text box help

    I can't think that it's been a very thorough search as this sort of thing is a fairly popular question. I saw a post earlier today on essentially the same topic if I'm not mistaken. There's even a thread dedicated to syntax highlighting in a RichTextBox in the VB.NET CodeBank forum. I would also think that reading the MSDN documentation for the RichTextBox would yield the members you needed to use, as they are quite few.

    Anyway, you can use IndexOf to find the next instance of the '#' character and set the SelectionStart property. You can then use IndexOf to find the end of the current line and set the SelectionLength property. You can then set the SelectionColor property. Repeat this procedure until you reach the end of the text.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2008] Rich text box help

    try this:

    vb Code:
    1. For x As Integer = 0 To RichTextBox1.Lines.GetUpperBound(0)
    2.     If RichTextBox1.Lines(x).StartsWith("#") Then
    3.       RichTextBox1.SelectionStart = RichTextBox1.GetFirstCharIndexFromLine(x)
    4.       RichTextBox1.SelectionLength = RichTextBox1.Lines(x).Length
    5.       RichTextBox1.SelectionColor = Color.Green
    6.     End If
    7. Next
    Last edited by .paul.; Nov 30th, 2008 at 02:05 PM.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2007
    Location
    indiana
    Posts
    341

    Re: [2008] Rich text box help

    with a little modification your code worked great. thanks for the help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width