DECLARE FUNCTION SetFocus LIB "user32" ALIAS "SetFocus" (hWnd AS LONG) AS LONG
DECLARE SUB RichEdit_onClick
DECLARE SUB RichEdit_Change (key AS BYTE)
DECLARE SUB LineNumbers_Click
DECLARE SUB Enumerate
DEFBYTE CR = 13
CREATE Form AS QFORM
Width = 300
Height = 150
Center
keyPreview = 1
onKeyUp = RichEdit_change
CREATE RichEdit AS QRICHEDIT
Left = 5
Top = 5
Text = "abcde"
END CREATE
CREATE Button AS QBUTTON
Left = 195
Top = 5
onclick = LineNumbers_Click
END CREATE
END CREATE
Form.SHOWMODAL
SUB RichEdit_onClick
RichEdit.SelectAll
SetFocus(RichEdit.Handle)
END SUB
SUB LineNumbers_Click
Enumerate
setfocus(RichEdit.handle)
END SUB
SUB RichEdit_Change (key AS BYTE)
IF Key = CR THEN
IF (richEdit.whereX +richEdit.whereY-1) > 0 THEN EXIT SUB
Enumerate
END IF
END SUB
SUB Enumerate
FOR i = 1 TO Richedit.LineCount
line$ = RichEdit.Line(i-1)
has% = INSTR("123456789", LEFT$(line$,1))
RichEdit.Line(i-1) = STR$(i) & " " &_
IIF(has%>0, RIGHT$(line$, LEN(line$)-INSTR(line$," ")), line$)
NEXT
END SUB
|