Results 1 to 2 of 2

Thread: RTF Colors

  1. #1

    Thread Starter
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    Want to be able to assign certain words certain colors without having to select it i.e.
    these commands
    selstart
    sellength
    i just need to to change automatically like the VB editor

    ------------------
    DiGiTaIErRoR

  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    Try this: (It does use selection, but it does not look like it is... Try it)

    Dim OldSelStart As Long
    RichTextBox1.TextRTF = "Hello World" ' Clear formatting and change text to Hello World
    OldSelStart = RichTextBox1.SelStart ' Remember old SelStart
    ' Color the Hello:

    RichTextBox1.SelStart = InStr(RichTextBox1.Text, "Hello") - 1
    RichTextBox1.SelLength = Len("Hello")
    RichTextBox1.SelColor = vbRed
    ' Color the World:
    RichTextBox1.SelStart = InStr(RichTextBox1.Text, "World") - 1
    RichTextBox1.SelLength = Len("World")
    RichTextBox1.SelColor = vbBlue
    ' Clear selection:
    RichTextBox1.SelStart = OldSelStart


    ------------------
    Yonatan
    Teenage Programmer
    E-Mail: [email protected]
    ICQ: 19552879



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