Results 1 to 5 of 5

Thread: RichEdit

  1. #1
    Member
    Join Date
    Mar 2009
    Location
    Netherlands
    Age
    49
    Posts
    248
    Rep Power
    37

    RichEdit

    Hi Guys,

    I have a question about the RichEdit class.

    I want to change the color of a word in a sentence. I know the begin and end position of this word that need another color, and I also know the Line number. How can I do that? I already saw the example with a color dialog box. But that's not the way i want to do it.

    I hope somebody can help me out...

    Martin

  2. #2
    Hi
    i have posted before "RichEdit, searching & coloring words" here... http://www.thinbasic.com/community/s...coloring-words to search for the word tiger and to know its position then to color it if we know its size.
    indeed due to the extreme complexity of the richedit i stopped to use it, and even i forgot how the attached code works.
    as you notice from the picture the coloring are shifted to the right every CRLF so you need to add a checking for CRLF in the code to correct the position of the "tiger" word at every CRLF.
    also i don't know how to enable the auto wrapping of text in the rich edit.
    i reattach the refered code above here
    also look at "RTF_AppendText" by catventure : http://www.thinbasic.com/community/p...hp?issueid=231
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	richedit.jpg 
Views:	96 
Size:	21.9 KB 
ID:	7539  
    Attached Files Attached Files

  3. #3
    i have found in my hard disk a vb6 example, in vb6 they wrap the API complexities in a simple syntax, i attach that small example to color the word "cat"
    Private Sub Command1_Click()Dim lPos As Long
    
    
    With RichTextBox1
      lPos = InStr(1, .Text, "cat")
      Do Until lPos = 0
      .SelStart = lPos - 1
          .SelLength = 3
          '.SelFontName = "courier"
          ' Your code to color the selection red
          .SelColor = vbRed
         lPos = InStr(lPos + 1, .Text, "cat")
      Loop
    End With
    
    
    End Sub
    
    Attached Files Attached Files

  4. #4
    A) I am using scintilla editor and recommend it to you:
    http://www.thinbasic.com/community/s...ight=scintilla

    B) try these code snippets:

    Global typo As String 
    Global ProgOpt As Options
    
    Type CHARFORMAT3
      cbSize As Long
      dwMask As DWord
      dwEffects As DWord
      yHeight As Long
      yOffset As Long
      crTextColor As DWord
      bCharSet As Byte
      bPitchAndFamily As Byte
      szFaceName As Asciiz * %LF_FACESIZE
      szDummy As Integer
    End Type 
    
    Function setRichTextColor( ByVal NewColors As Long) As Long
        Local cf As CHARFORMAT3
    
        cf.cbSize      = Len(cf)
        cf.dwMask      = %CFM_COLOR
        cf.crTextColor = NewColors
    
        Call SendMessage(myEdit, %EM_SETCHARFORMAT, %SCF_SELECTION, VarPtr(cf))
    
    End Function
    
    second:

    Type Options
        ShowOnStartup   As Long
        KeywordsColor   As Long
        EquatesColor    As Long
        StringsColor    As Long
        RemColor        As Long
        LastScripts(5) As String * 255
        LastScriptsNum  As Long
    End Type
    ...
    
    (use in 1) callback part or 2) scanline part for word parser )
    
    CALL setRichTextColor (ProgOpt.KeywordsColor)         'set typo to specific color you wished! :)
    ...
    
    3) you can use a colorpicker to colorize a single word you like too

    bye, largo
    Last edited by largo_winch; 17-10-2011 at 14:58.

  5. #5
    Member
    Join Date
    Mar 2009
    Location
    Netherlands
    Age
    49
    Posts
    248
    Rep Power
    37
    Thanks a lot to both of you for your quick replies. I will give it a try soon!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •