PDA

View Full Version : RichEdit



martin
17-10-2011, 10:50
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

zak
17-10-2011, 12:03
Hi
i have posted before "RichEdit, searching & coloring words" here... http://www.thinbasic.com/community/showthread.php?10748-RichEdit-searching-amp-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/project.php?issueid=231

zak
17-10-2011, 13:27
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

largo_winch
17-10-2011, 14:19
A) I am using scintilla editor and recommend it to you:
http://www.thinbasic.com/community/showthread.php?11171-scintilla-%28texteditor%29-example-%29&highlight=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

martin
17-10-2011, 17:57
Thanks a lot to both of you for your quick replies. I will give it a try soon!