奇怪ADD OBJECT与AddObject()效果完全不同
下面分别用这2种方法,增加一个自定义的类,目的是容器cnt的大小根据label的大小变化,结果 用add object 的可以,但addobject()的没变化of = CREATEOBJECT("form1")
of.Height =600
of.Width = 800
of.show(1)
CLEAR ALL
RETURN
DEFINE CLASS form1 as Form
ADD OBJECT "Cmd1" as commandbutton
Cmd1.top =10
Cmd1.left = 10
PROCEDURE Cmd1.Click
WITH thisform
.AddObject("Cnt2","Cnt")
.Cnt2.top =100
.Cnt2.left= 400
.Cnt2.visible = .t.
.Cnt2.label1.caption = "哈哈哈哈哈哈哈哈"
ENDWITH
ENDPROC
ADD OBJECT "Cnt1" as Cnt
Cnt1.top =100
Cnt1.left= 10
Cnt1.label1.caption = "哈哈哈哈哈哈哈哈"
ENDDEFINE
DEFINE CLASS "Cnt" as Container
Height = 50
Width = 100
ADD OBJECT Label1 as Label WITH BackStyle = 0,AutoSize = .t.,top = 5,left = 5
PROCEDURE Init
this.Width = this.Label1.Width + 10
ENDPROC
ENDDEFINE