例程:
import win.ui;
/*DSG{{*/
wform = win.form(text="AddCtrl";right=880;bottom=543;max=false)
wform.add(
button={cls="button";text="开始";left=8;top=189;right=75;bottom=247;flat=1;z=1};
map={cls="custom";text="自定义控件";left=0;top=261;right=876;bottom=537;bgcolor=15793151;border=1;z=2}
)
/*}}*/
var mpxy={};//x,y,width,height,text,indexId : {105,210,55,35,"M0101",1} //定义控件属性
var mcount=0;//记录控件数量
var mxy={
{100,210,55,35},
{100,170,55,35},
{45,105,55,35},
{45,65,55,35},
{75,5,55,35}
}; //定义控件起始显示区域
initmpxy=function(xy){
var d=0;
var id=0;
for(i=1;14;1){
d=(i-1)*xy[1][3];
id++;
table.push(mpxy,{xy[1][1]+d,xy[1][2],xy[1][3],xy[1][4],"M01"+string.right("0"+i,2),id})
id++;
table.push(mpxy,{xy[2][1]+d,xy[2][2],xy[2][3],xy[2][4],"M02"+string.right("0"+i,2),id})
id++;
table.push(mpxy,{xy[5][1]+d,xy[5][2],xy[5][3],xy[5][4],"M05"+string.right("0"+i,2),id})
}
for(i=1;15;1){
d=(i-1)*xy[1][3];
id++;
table.push(mpxy,{xy[3][1]+d,xy[3][2],xy[3][3],xy[3][4],"M03"+string.right("0"+i,2),id})
id++;
table.push(mpxy,{xy[4][1]+d,xy[4][2],xy[4][3],xy[4][4],"M04"+string.right("0"+i,2),id})
}
mcount=id;
}//初始化控件区域和位置
initmpxy(mxy)
wform.button.oncommand = function(id,event){
//在窗体上动态添加控件和事件
for(i=1;mcount;1){
var sc=mpxy[i][5];
wform.add( [sc]={cls="button";bottom=mpxy[i][2]+mpxy[i][4];right=mpxy[i][1]+mpxy[i][3];left=mpxy[i][1];top=mpxy[i][2];z=1;text=mpxy[i][5];id=i+100;autoResize=false;hide=1;edge=1}; )//hide=1为默认隐藏,这样显示的时候不会闪烁
wform[sc].oncommand=function(id,event){
win.msgbox(sc,mpxy[i][6],0,0);
}
}
for(i=1;mcount;1){
wform[mpxy[i][5]].show();
}
//在可视控件内动态添加控件和事件
var bt="";
for(i=1;mcount;1){
bt=mpxy[i][5];
wform.map.addCtrl([bt]={cls="button";text=mpxy[i][5];left=mpxy[i][1]+1;top=mpxy[i][2];right=mpxy[i][1]-2+mpxy[i][3];bottom=mpxy[i][2]+mpxy[i][4];id=i+300;autoResize=false;
oncommand=function(id,event){
win.msgbox(bt,"控件内:"+ mpxy[i][6],0,0);
}
})
}
}
wform.button.wndproc = function(hwnd,message,wParam,lParam){
//wform.cmdTranslate(hwnd,message,wParam,lParam);
}//新版的aardio 不用加这句也可以执行动态控件的事件
wform.show();
return win.loopMessage();