Colleagues,
I am trying to reproduce the typical Find (text) behavior of any text editor in my VFP form with RichEdit ActiveX embedded. That is, user highlights some substring in the text currently displayed in the RichTextBox control, hits the Find button (VFP's native) and the next example of such substring is highlighted. Well, while the program does find next matching substring, it never highlights it.
Here's what I tried so far:
in the FORM.oRTF.SelChange event procedure, i.e.
and it works as it's supposed to.
Then, in the FORM.cmdFind.Click event procedure, I have
I tried it with and without assigning RTF's SelText property (in the line commented just above) - result was the same: the found instance of the sought substring was not highlighted.
The RichTextBox (or RichText Edit?) control is the one that came with Visual Studio 6.
The rest is VFP9SP2.
What am I doing wrong?
Regards,
Ilya
I am trying to reproduce the typical Find (text) behavior of any text editor in my VFP form with RichEdit ActiveX embedded. That is, user highlights some substring in the text currently displayed in the RichTextBox control, hits the Find button (VFP's native) and the next example of such substring is highlighted. Well, while the program does find next matching substring, it never highlights it.
Here's what I tried so far:
in the FORM.oRTF.SelChange event procedure, i.e.
Code:
WITH THISFORM
.GetCursorLinePos() && Just another custom method I added to display the cursor's position
.c_SelectedTxt = IIF(.oRTF.SelLength == 0, "", ;
SUBSTR(.oRTF.Text, .oRTF.SelStart + 1, .oRTF.SelLength) ;
) && Add 1 position coz RichTextBox's counting is 0-based
ENDWITH
Then, in the FORM.cmdFind.Click event procedure, I have
Code:
LOCAL lcStr2Find, lnStrLen, lnFindStart, lnRet
IF THISFORM.oRTF.SelLength == 0
RETURN
ENDIF ()
lcStr2Find = THISFORM.c_SelectedTxt
IF EMPTY(lcStr2Find) && Nothing to look for!
RETURN
ENDIF (EMPTY(lcStr2Find) && Nothing to look for!)
lnStrLen = LEN(lcStr2Find)
lnFindStart = THISFORM.oRTF.SelStart + 1 + THISFORM.oRTF.SelLength && Add 1 coz RichTextBox counting is 0-based
lnRet = THISFORM.oRTF.Find(lcStr2Find, lnFindStart)
IF lnRet < 0 && Sought substr was not found
WAIT WINDOW NOWAIT [ Substring "] + lcStr2Find + [" was not found. ]
RETURN
ENDIF (lnRet < 0 && Sought substr was not found)
WITH THISFORM.oRTF
.SelStart = lnRet && lnFindStart
.SelLength = lnStrLen
** .SelText = lcStr2Find
ENDWITH
I tried it with and without assigning RTF's SelText property (in the line commented just above) - result was the same: the found instance of the sought substring was not highlighted.
The RichTextBox (or RichText Edit?) control is the one that came with Visual Studio 6.
The rest is VFP9SP2.
What am I doing wrong?
Regards,
Ilya