Results 1 to 5 of 5

Thread: Select Specific Text in the RichTextBox

  1. #1

    Thread Starter
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    Select Specific Text in the RichTextBox

    Ok I have a RichTextBox, which is used as the main chat window of my app.

    So it would be like,
    User1: Message
    User2: Message

    I want to bold the "User1:" and "User2:"

    I was thinking I might search along the line until I find the first :

    But of course I don't have any code for this, any help would be great.
    Don't Rate my posts.

  2. #2
    Lively Member
    Join Date
    Feb 2000
    Location
    Glasgow, Scotland
    Posts
    71
    Hi,

    You could use instring to find the position of the ':' then SelStart SelLength to select the text and then make it bold.

    Hope this helps,

    Chris

  3. #3
    Lively Member
    Join Date
    Apr 2002
    Location
    India
    Posts
    105
    In richtextbox lines can not be read, otherwise ur problem would be easy.
    try this,


    Dim MyPos as integer
    Private Sub Command1_Click()
    tmpstr = "User1:"
    With RichTextBox1
    MyPos = Len(.Text)
    .Text = .Text + vbCrLf + tmpstr
    .SelStart = MyPos + 2
    .SelLength = 5
    .SelBold = True
    End With
    End SUb
    Shahab Ahmed

  4. #4

    Thread Starter
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    Hmm thats going to be hard, as I'm not sure what the Username will be.
    Don't Rate my posts.

  5. #5
    Lively Member
    Join Date
    Apr 2002
    Location
    India
    Posts
    105
    I hope this works,
    VB Code:
    1. Dim mypos As Integer
    2. Private Sub Command1_Click()
    3. Dim Position As Integer
    4. tmpstr = txtusernm.text & ":" & txtmsg.text
    5. With RichTextBox1
    6.     mypos = Len(.Text)
    7.     .Text = .Text + vbCrLf + tmpstr
    8.     Position = 0
    9.     Position = .Find(":", mypos + 1, , FindFlags)
    10.     If Position >= 0 Then
    11.         .SelStart = mypos + 2
    12.         .SelLength = Position - (mypos + 1)
    13.         .SelBold = True
    14.     End If
    15. End With
    16. End Sub
    Shahab Ahmed

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