Results 1 to 5 of 5

Thread: Text Formating

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    313

    Text Formating

    Does anyone know of a good way to format text like if the user types the word yes turn it blue and if the user types no turn it red, or if they type a number turn it brown? I was going to use a rich text box and just check it in the TextChanged section but my problem is to change the color or size or what not i would have to select the text. So what it is kind of like is like visual basic or C++ how do those programs change the text on the fly? And also how do they put those ~~~~~~ wavy lines below the problem areas like microsoft word does when you spell something wrong?

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    One way to highlight the words as they are typing them in is to use the keypress event. Don't scan the whole rtb everytime though, it would be too slow. What you do is store the last 25 (or as many as you think you need) characters typed in a static variable. Every time a user types a new character, you add it to the string at the end, remove the first, then scan that string for what your looking for. Make changes, then post those changes to the rtb. This stops the scanning of the whole document every time, and would end up saving a lot of time if the document was huge.

    There are many other ways to do it though, mine is just one. There might be a lot better ways.

  3. #3
    Hyperactive Member
    Join Date
    Nov 2002
    Location
    india
    Posts
    418
    hi,

    use richtextbox1.selcolor=vbgreen

  4. #4
    Fanatic Member laserman's Avatar
    Join Date
    Jan 2002
    Location
    Wales U.K
    Posts
    775
    What abot something like this:-

    VB Code:
    1. Private Sub Form_Load()
    2. Text1.Text = vbLowerCase
    3. End Sub
    4.  
    5. Private Sub Text1_Change()
    6.  
    7. If Text1.Text = "yes" Then
    8.     Text1.ForeColor = vbBlue
    9.  
    10.     ElseIf Text1.Text = "no" Then
    11.             Text1.ForeColor = vbRed
    12.         Else
    13.  
    14.     End If
    15.             If IsNumeric(Text1.Text) = True Then
    16.                     Text1.ForeColor = vbGreen
    17.  
    18. End If
    19.  
    20.  
    21.  
    22. End Sub

  5. #5
    Fanatic Member laserman's Avatar
    Join Date
    Jan 2002
    Location
    Wales U.K
    Posts
    775
    This may be a littlre better. Sorry for the formatting but i have 1 minute before i go

    Try this

    VB Code:
    1. Private Sub Form_Load()
    2. Text1.Text = vbLowerCase
    3. End Sub
    4.  
    5. Private Sub Text1_Change()
    6.  
    7. If Text1.Text = "yes" Then
    8.     Text1.ForeColor = vbBlue
    9.  
    10.     ElseIf Text1.Text = "no" Then
    11.                 Text1.ForeColor = vbRed
    12.     ElseIf IsNumeric(Text1.Text) = True Then
    13.              Text1.ForeColor = vbGreen
    14.              
    15.     ElseIf Text1.Text <> yes And Text1.Text <> no And IsNumeric(Text1.Text) = False Then
    16.             Text1.ForeColor = vbBlack
    17.        
    18.    
    19.  
    20. End If
    21.  
    22.  
    23. End Sub

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