PDA

Click to See Complete Forum and Search --> : Since you guys are the only ones who listen to me...


Sastraxi
Mar 16th, 2001, 02:01 PM
They wont listen to be at the General or API forums. You will only listen to me if I post here, so here I go.

I've got a Q. I've been trying to use the RTB control to do an editing environment, but it's not working. I want all of the words in the box that are in the Keywords() array to become blue, like in VB. Now I've tried:

1. Finding them and modifying them to no avail.
2. Having a second off-screen RTB and changing them there. Works, but always sets the caret to the start of the document, resulting in backwards text:

Here is my text.
.txet ym si ereH

Is there any other control where I can use HTML-like formatting to do this? Or is there an alternative to the rich text box? I dont want to use an RTB or something that looks unproffesional, for this is for my upcoming APP, JavaPad, freeware for Java Programmers.

Can you guys help me?

Fox
Mar 16th, 2001, 02:13 PM
poor guy ;)


I think your problem is to always set the position of the cursor... SelStart=...

no time to test that out, sorry

Mar 16th, 2001, 02:46 PM
Mmk. Here I go. Its pretty simple. First, for the highlighting funtion.

Private Sub highlight()
rtb.SelStart = 1
rtb.SelLength = Len(Box.Text)
rtb.SelColor = RGB(0, 0, 0)
For j = 0 To numkeywords - 1
For i = 1 To Len(rtb.Text)
If InStr(i, LCase(rtb.Text), LCase(keywords(j))) Then
With rtb
.SelStart = InStr(i, LCase(rtb.Text), LCase(keywords(j))) - 1
.SelLength = Len(keywords(j))
.selcolor = RGB(0, 0, 255)
End With
i = InStr(i, LCase(rtb.Text), LCase(keywords(j)))
End If
Next i
Next j
End Sub

That finds all of the keywords, and highlights them.
To make it work well, only use that sub when the user presses Enter, Up or Down.

Z.

[edit]
FIxed the highlight function. Now it clears the previous highlights before highlighting.