谢谢csyx ,没有vfp代码示例
[此贴子已经被作者于2025-9-12 05:34编辑过]
程序代码:Declare Long GetCaretPos in win32api String @
pt = BinToC(0,'rs') + BinToC(0,'rs')
GetCaretPos(@ pt)
x = CToBin(Substr(pt,1,4), 'rs')
y = CToBin(Substr(pt,5,4), 'rs')
cc = Substr(This.Text, This.SelStart+1, 1)
Do case
Case IsLeadByte(cc)
cc = ["] + Substr(This.Text, This.SelStart+1, 2) + ["]
Case Asc(cc) < 33
cc = Textmerge('CHR(<<Asc(cc)>>)')
Otherwise
cc = ["] + cc + ["]
EndCase
cc = Textmerge('char=<<cc>>,x=<<x>>,y=<<y>>')
Wait windows cc nowait noclear

程序代码:
of = CREATEOBJECT("form1")
of.show(1)
CLEAR ALL
RETURN
DEFINE CLASS form1 as Form
width = 500
height = 400
AllowOutput = .f.
AutoCenter = .t.
FontSize = 18
word = ""
ADD OBJECT label1 as label WITH left= 50,top=300,width=50,height=28,fontsize=18,caption="填"
ADD OBJECT label2 as label WITH left=110,top=300,width=50,height=28,fontsize=18,caption="空"
ADD OBJECT label3 as label WITH left=170,top=300,width=50,height=28,fontsize=18,caption="选"
ADD OBJECT label4 as label WITH left=230,top=300,width=50,height=28,fontsize=18,caption="择"
PROCEDURE label1.click
thisform.selWord(this)
ENDPROC
PROCEDURE label2.click
thisform.selWord(this)
ENDPROC
PROCEDURE label3.click
thisform.selWord(this)
ENDPROC
PROCEDURE label4.click
thisform.selWord(this)
ENDPROC
FUNCTION selWord(obj)
this.word = obj.Caption
obj.ForeColor = 0x000000FF
INKEY(0.1)
obj.ForeColor = 0x00FF0000
ENDFUNC
PROCEDURE init
txt = "请先 _ 点击下面 _ 选择要填空的内容,然后 _ 再点击上面 _ 要填空的下划线 _ 的空位置"
DIMENSION aLowLine[OCCURS("_",txt),2]
lowline = 0
this.CurrentX = 10
this.CurrentY = 10
FOR i=1 TO LENC(txt)
word = SUBSTRC(txt, i, 1)
IF word == "_"
lowline = lowline + 1
aLowLine[lowline,1] = this.CurrentX + this.TextWidth ("_")/2
aLowLine[lowline,2] = this.CurrentY + this.TextHeight("_")/2
ENDIF
this.Print(word)
IF this.CurrentX > this.Width - 50
this.CurrentX = 10
this.CurrentY = this.CurrentY + this.TextHeight(SUBSTRC(txt, i+1, 1)) + 10
ENDIF
ENDFOR
ENDPROC
PROCEDURE click
this.printf(this.word)
ENDPROC
FUNCTION printf(word)
AMOUSEOBJ(arr)
this.CurrentX = arr[3]-this.TextWidth (word)/2
this.CurrentY = arr[4]-this.TextHeight(word)/2
**可以判断当前点击的(x,y)与aLowLine数组保存的各"_"(x,y)是否有匹配才决定下一步。
this.Print(word)
ENDFUNC
ENDDEFINE
程序代码:
of = CREATEOBJECT("form1")
of.show(1)
CLEAR ALL
RETURN
DEFINE CLASS form1 as Form
width = 500
height = 400
AllowOutput = .f.
AutoCenter = .t.
FontSize = 18
word = ""
DIMENSION aLowLine[1,2]
ADD OBJECT label1 as label WITH left= 50,top=300,width=50,height=28,fontsize=18,caption="填"
ADD OBJECT label2 as label WITH left=110,top=300,width=50,height=28,fontsize=18,caption="空"
ADD OBJECT label3 as label WITH left=170,top=300,width=50,height=28,fontsize=18,caption="选"
ADD OBJECT label4 as label WITH left=230,top=300,width=50,height=28,fontsize=18,caption="择"
PROCEDURE label1.click
thisform.selWord(this)
ENDPROC
PROCEDURE label2.click
thisform.selWord(this)
ENDPROC
PROCEDURE label3.click
thisform.selWord(this)
ENDPROC
PROCEDURE label4.click
thisform.selWord(this)
ENDPROC
FUNCTION selWord(obj)
this.word = obj.Caption
obj.ForeColor = 0x000000FF
INKEY(0.1)
obj.ForeColor = 0x00FF0000
ENDFUNC
PROCEDURE init
txt = "请先 _ 点击下面 _ 选择要填空的内容,然后 _ 再点击上面 _ 要填空的下划线 _ 的空位置"
DIMENSION this.aLowLine[OCCURS("_",txt),2]
lowline = 0
this.CurrentX = 10
this.CurrentY = 10
FOR i=1 TO LENC(txt)
word = SUBSTRC(txt, i, 1)
IF word == "_"
lowline = lowline + 1
this.aLowLine[lowline,1] = this.CurrentX + this.TextWidth ("_")/2
this.aLowLine[lowline,2] = this.CurrentY + this.TextHeight("_")/2
ENDIF
this.Print(word)
IF this.CurrentX > this.Width - 50
this.CurrentX = 10
this.CurrentY = this.CurrentY + this.TextHeight(SUBSTRC(txt, i+1, 1)) + 10
ENDIF
ENDFOR
ENDPROC
PROCEDURE click
this.printf(this.word)
ENDPROC
FUNCTION printf(word)
AMOUSEOBJ(arr)
this.CurrentX = arr[3]-this.TextWidth (word)/2
this.CurrentY = arr[4]-this.TextHeight(word)/2
**可以判断当前点击的(x,y)与aLowLine数组保存的各"_"(x,y)是否有匹配才决定下一步。
IF this.isLowLine(arr[3], arr[4])
this.Print(word)
ENDIF
ENDFUNC
FUNCTION isLowLine(x, y)
FOR i=1 TO ALEN(this.aLowLine,1)
IF ABS(this.aLowLine[i,1] - x) < this.TextWidth ("_")/4 AND ;
ABS(this.aLowLine[i,2] - y) < this.TextHeight("_")/4
RETURN .t.
ENDIF
ENDFOR
RETURN .f.
ENDFUNC
ENDDEFINE