Results 1 to 11 of 11

Thread: [RESOLVED]Rich Text Box woes

  1. #1

    Thread Starter
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Resolved [RESOLVED]Rich Text Box woes

    I'm having a few problems with the RTB control, and no ammount of googling or forum-sniffing brought the requred info.

    First of all, how can I highlight the selected text(with a color, not the default)? On this forum, I've stumpled upon a technique of drawing a texbox with the text and the fill color as the background, but it's very inelegant, and hard to get right(calculating the position on variable font\box sizes is really annoying). I know RTF files are capable of holding hilight info, and the control is capable of displaying is, but how to apply it in runtime...?

    Next, is there a way to detect how long is a visible line(not anything ending with a line break, but the one displayed in the control)? The font I'm using is Times New Roman, so it won't be possible to check the length by getting the characters. And words are wrapped anyway.

    Thanx in advance.
    Last edited by Max_aka_NOBODY; Apr 14th, 2005 at 07:59 AM.

  2. #2
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: Rich Text Box woes

    This may be able to answer at least some of your questions:
    http://www.thevbprogrammer.com/index...ter=10&Topic=6
    "It's cold gin time again ..."

    Check out my website here.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Rich Text Box woes

    Quote Originally Posted by Max_aka_NOBODY
    can I highlight the selected text(with a color, not the default)? On this forum, I've stumpled upon a technique of drawing a texbox with the text and the fill color as the background, but it's very inelegant, and hard to get right(calculating the position on variable font\box sizes is really annoying). I know RTF files are capable of holding hilight info, and the control is capable of displaying is, but how to apply it in runtime...?
    Try something like this
    VB Code:
    1. Dim arrStringArray() As String
    2. Dim lngPos As Long
    3. Dim lngLoop As Long
    4. With Richtextbox1
    5.      arrStringArray() = Split(.Text, vbCrLf)
    6.      For lngLoop = 0 To UBound(arrStringArray)
    7.           If InStr(arrStringArray(lngLoop), "Words Or String to Highlight") Then
    8.              .SelStart = lngPos
    9.              .SelLength = Len(arrStringArray(lngLoop))
    10.              .SelBold = True
    11.              .SelColor = vbRed
    12.           End If
    13.           lngPos = .Find(vbCrLf, lngPos) + 2
    14.       Next
    15. End With
    You can put that into a sub and pass it the string to highlight along with the color of choice

  4. #4

    Thread Starter
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: Rich Text Box woes

    Thanx. Nice tutorial there, Bruce, but it still doesn't answer my main question.

    Thanx for taking the time to write the code, Hack, but you've misunderstood my question. I'm asking for a way to add highlighting, by which I mean fill color. I don't mind using SendMessage -- or any other API to that matter -- as it seems that the RTF doesn't have the functionality I need exposed, or is it just my ignorance?

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Rich Text Box woes

    Here is a simple example that does colors.
    Attached Files Attached Files

  6. #6
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: Rich Text Box woes

    Sorry Max, I did not understand originally that you were looking for the backcolor (fill color / highlight) as opposed to the forecolor or text color. I did not look at Dave's example yet, but hopefully he has what you need.
    "It's cold gin time again ..."

    Check out my website here.

  7. #7

    Thread Starter
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: Rich Text Box woes

    Nope, unfortunately DG did the forecolor as well.

    [EDIT]
    I've attached the project I'm doing this for. Right now I'm using coloring, but I'd prefer to use a hilighting fill.
    Attached Files Attached Files
    Last edited by Max_aka_NOBODY; Apr 13th, 2005 at 03:53 PM.

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Rich Text Box woes

    Sorry. I have two versions of that. Here is the other one, misfiled under COLOR instead of RTF

    It does back coloring


    EDITED: Sorry. Fixed it.
    Attached Files Attached Files
    Last edited by dglienna; Apr 13th, 2005 at 04:58 PM.

  9. #9

    Thread Starter
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: Rich Text Box woes

    I think it got mixed up again.

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Rich Text Box woes

    I replaced it with the right one.

  11. #11

    Thread Starter
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: Rich Text Box woes

    Mucho Gracias!

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