根据微调按钮动态增加控件,表单实例化后,怎么加控件?
用设计器做的是这样的:原来的想法是,先都展现出来,但readOnly三行,第一行肯定是要有的,当微调等于2,第二行解禁,依此类推,重刷表单
后来感觉不帅,就想用代码动态增加
程序代码:
CLEAR ALL CLOSE PROCEDURES SET PROCEDURE TO "MyForm", "MyLogin","otherForm" runOtherForm1() CLOSE PROCEDURES &&CLOSE ALL return PROCEDURE runOtherForm1 PUBLIC otherForm1 otherForm1=CREATEOBJECT("m1Form") otherForm1.show READ EVENTS RETURN ENDPROC DEFINE CLASS m1Form as myForm showWindow=2 caption="功能模块1窗口" autoCenter=.t. windowType=1 ADD OBJECT howManyLine as spinner WITH spinnerHighValue=4,spinnerLowValue=1,value=1,left=180 ADD OBJECT button1 as commandButton WITH caption="返回主程序" &&根据微调按钮,增加条目开始 ADD OBJECT clfl1 as textBox WITH top=135,left=12,height=24,width=48,value="材料分类1" ADD OBJECT clmc1 as textBox WITH top=135,left=63,height=24,width=77,value="材料名称1" PROCEDURE init MESSAGEBOX(thisform.howManyLine.value,64,"调试:微调的值是Value吗?") ENDPROC PROCEDURE howManyLine.valid howLine=thisform.howManyLine.value IF howLine>=2 FOR addLine=2 TO howLine flName="clfl"+ALLTRIM(STR(addLine)) &&用宏代实现分类名称和材料名称,不知道怎么样? clName="clmc"+ALLTRIM(STR(addLine)) &&或者用这个先确定名称 MESSAGEBOX(clName,64,"运行了吗?") ADD OBJECT &flName as textBox WITH top=135+addLine,left=12,height=24,width=48,value="材料分类"+ALLTRIM(STR(addLine)) ADD OBJECT &clName as textBox WITH top=135+addLine,left=63,height=24,width=77,value="材料名称"+ALLTRIM(STR(addLine)) ENDFOR ENDIF thisform.refresh ENDPROC &&根据微调按钮,布局结束 PROCEDURE button1.click RELEASE thisform ENDPROC PROCEDURE Destroy MESSAGEBOX(thisform.clmc2.value,64,"控件增加了吗?") MESSAGEBOX("模块1表单销毁了",64,"123") CLEAR EVENTS ENDPROC ENDDEFINE
可是 发现自己不会实例化表单后 再增加控件 。。。