Results 1 to 8 of 8

Thread: changing text color in a rich text box

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183
    two fairly easy ones (hopefully!):

    I want to change the text color in a rich text box any idea?
    And:
    For some reason the tab button makes the cursor disapear out of my rich text box, know how to fix this?

    Anybody have any ideas?

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Question 1
    http://forums.vb-world.net/showthrea...threadid=32197

    Question 2
    Code:
    'You can set the Tabstop property to false for all the controls: 
    'disable the tab form
    
    Private Sub Form_Load() 
    	Dim i As Integer 
    	On Error Resume Next 
    	For i = 0 To Controls.Count - 1   ' Use the Controls collection 
       		Controls(i).TabStop = False 
    	Next 
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    1. Set the SelColor property to what ever you want.

    Code:
    rtxt.SelColor = vbRed
    2. To enable the tab as a tab key, so that is does not tab to the next control, you need to set all of the other controls TabStop property to false.

    You do that in the Got_Focus event. Then set them back to true in the lost_focus event.

    Code:
    Dim myControl as Control
    
    For Each myControl In Controls
      myControl.TabStop = False
    Next
    Iain, thats with an i by the way!

  4. #4
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Posts
    141
    To Set Color, find the text and change the color:

    Code:
     Private Sub Find_Text(strFindText As String)
        Dim FoundPos As Integer
        
        'Find the text specified in the strFindText Parameter.
        FoundPos = RichTextBox1.Find(strFindText, , , rtfWholeWord)
        
        'If found then change the color.
        If FoundPos <> -1 Then
            'Set Color of found text to Red
            RichTextBox1.SelColor = vbRed
        End If
    End Sub

    Disable TabStop for Controls When Entering A RichText Box
    so pressing the tab key doesn't cause the focus to be set
    to the next control in the tabindex order.
    Code:
    Private Sub RichTextBox1_GotFocus()
        Dim Control As Control
        'Ignore errors for controls without the TabStop property.
        On Error Resume Next
        'Switch off the change of focus when pressing TAB.
        For Each Control In Controls
            Control.TabStop = False
        Next Control
    End Sub
    Make sure you Re-Enable TabStop for Controls When Leaving
    the RichText Box so pressing the tab key does set focus
    to the next control.
    Code:
    Private Sub RichTextBox1_LostFocus()
        Dim Control As Control
        'Ignore errors for controls without the TabStop property.
        On Error Resume Next
        'Switch off the change of focus when pressing TAB.
        For Each Control In Controls
            Control.TabStop = True
        Next Control
    End Sub
    -- HeSaidJoe and Iain are must be faster typers than me.
    There weren't any posts when I started this.
    JC

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    jcouture100
    On my part, no typing...searchable mdb Cut 'n Paste
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362

    Rich Text Boxes

    Private1 posted a thread wanting to copy 1 line of a RTB (by clicking a button) to another RTB maintaining font,
    color, underline, etc, etc. The second RTB should have a CrLf after each entry, i.e.
    each line typed into RTB1 should be on a separate line in RTB2. I'm not to keen on RTBs and
    I've been grappling with this all day.

    I can get the RTB1 lines to print in the correct format (colors, etc) but can't seem to
    get them on separate lines.

    Any advice?

    [Edited by dsy5 on 09-24-2000 at 07:58 PM]
    Donald Sy - VB (ab)user

  7. #7
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Posts
    141
    I really would suggest you post this question in a new
    thread to get more responses. I doubt the guru's out there
    will be reading a post that already has 5 other posts on it.

    But with that in mind, I guess I really don't understand the
    problem. I haven't had any problem adding carriage returns
    in RichTextBoxes. I threw together a little chat type
    window and put the contents of one RTB into another with
    a leading vbCrLf without any problems. Here is the code I
    used...

    Code:
        'Add text from RTB2 to end of RTB1.  Separate with
        'a Carriage Return.
        rtb1.Text = rtb1.Text & vbCrLf & rtb2.Text
    
        'Clear RTB2
        rtb2.Text = ""
        'Set focus back to RTB2
        rtb2.SelStart = 0
        rtb2.SetFocus
    Hope this helps.
    JC

  8. #8
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    jcouture100

    The problem wasn't adding a CrLf, but keeping the copied text with the same formatting (color, etc).
    All on separate lines.

    It's not really my problem, but trying to help out Private1 I found I could not do it. I'm not very familiar with RTBs, so I will try what you posted.

    If you're interested, I will post Private1's code that I was attempting to help him with.
    (I believe he copied it from a demo from here or Vb Square).
    Donald Sy - VB (ab)user

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