Results 1 to 3 of 3

Thread: how to color a word

  1. #1

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    60

    how to color a word

    HI everybody

    I want to know how can i do to search a word in a richtextbox to count it and to color it , in yellow for example

    this is my code , and i think it's incomplete and probably wrong


    dim n as integer
    dim t as string
    for each t in richtextbox1.text
    if t="hello" then
    n=n+1
    end if
    next
    'It doesn't works actually , can you help me

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: how to color a word

    Use the "SelectionStarts", "SelectionLength", "SelectionColor" properties
    I think that's a good hit
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: how to color a word

    Something like this should help you implement it your way:
    Code:
            Dim rtbText As String = RichTextBox1.Text
            Dim ColoredString As String = "hello"  'it is case sensitive
    
            Dim Index As Integer
    
            Index = rtbText.IndexOf(ColoredString)
            Do While Index > 0
                Index = rtbText.IndexOf(ColoredString, Index + 1)
    
                If Index <> -1 Then
                    RichTextBox1.Select(Index, ColoredString.Length)
                    RichTextBox1.SelectionColor = Color.Yellow
                End If
            Loop
    VB 2005, Win Xp Pro sp2

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