以下是引用有容就大在2012-9-23 22:19:42的发言:
而且发现BindEvent()的一个不足就是把命令按钮的CLICK托管到Form后 只要在Form上任意一点点击都将实现点击结果。。。。
这个。。这个。。
而且发现BindEvent()的一个不足就是把命令按钮的CLICK托管到Form后 只要在Form上任意一点点击都将实现点击结果。。。。
这个。。这个。。
把那个Click事件换成别的自定义名字,不用内置的事件名字也可以。

授人以渔,不授人以鱼。
程序代码: If .Key.ask_Button == .T.
.AddObject("Ctnr_Button","CommandButton")
With This.Ctnr_Button
.Height = 30
.Caption = This.Key.btn_Caption
.Left = This.Ctnr_Text.Left + This.Ctnr_Text.Width + ln_Space
.Top = This.Key.chg_Height / 2 - .Height / 2
.Width = 100
EndWith
Do case
Case This.Key.ID == "Number"
BindEvent(.Ctnr_Button, "Click", This, "Click_Number")
EndCase
EndIf
.SetAll("Visible", .T.)
.SetAll("FontSize", 16)
.SetAll("Alignment", 2)
.SetAll("FontBold", 1)
.Height = .Key.chg_Height
EndWith
EndProc
Procedure Click_Number
MessageBox("Hhahaha")
EndProc


程序代码:
DEFINE CLASS C_Form AS Form
PROCEDURE Init
FOR i = 1 TO 8
lc_Name = "xx" + TRANSFORM(i)
ThisForm.AddObject(lc_Name, "myClass")
WITH ThisForm.&lc_Name
.Label1.Caption = "Caption + " + TRANSFORM(i)
.Height = 20 + 5 * (i - 1)
.Width = 200
.Visible = .T.
.Resize
ENDWITH
IF i == 2
BindEvent(ThisForm.&lc_Name..Label1, "Click", This, "Click1")
ENDIF
NEXT
ENDPROC
PROCEDURE Click1
ThisForm.xx.Label1.Caption = "bbb"
ENDPROC
ENDDEFINE
DEFINE CLASS myClass AS Container
ADD OBJECT Label1 AS Label WITH Caption = "aaa"
ADD Object TextBox1 AS TextBox
PROCEDURE Resize
WITH This
.SetAll("Height", .Height)
ENDWITH
ENDPROC
PROCEDURE TextBox1.Valid
IF EMPTY(This.Value)
RETURN .F.
ENDIF
ENDPROC
ENDDEFINE
