第一种,直接创建(其实就是根据系统的类名创建)
CommandButton lbtn_new
lbtn_new = Create CommandButton
lbtn_new.Width = 300
lbtn_new.Height = 100
lbtn_new.visible = true
lbtn_new.Text = "new"
parent.OpenUserObject(lbtn_new,"commandbutton",this.x + 600 , this.y)
第二种,根据自己的类名创建
CommandButton lbtn_new
lbtn_new = Create using "cb_1"
lbtn_new.text = " new cb_1"
parent.OpenUserObject(lbtn_new,"cb_1",this.x + 600 , this.y)
网上找的其他资料
动态创建一CommandButton,并使之能响应Click事件
动态创建按钮不难,如下
CommandButton MyCmdBtn //声明
OpenUserObject(MyCmdBtn, "CommandButton", 100, 100) //创建
MyCmdBtn.Width = 600 //设置属性
MyCmdBtn.Height = 150
MyCmdBtn.Text = "这是一个动态创建的控件!"
MyCmdBtn.Visible = TRUE
//放入父对象的子控件队列中
Parent.Control[ UpperBound( Parent.Control ) + 1] = MyCmdBtn
但是:如何将一个事件绑定给他呢?
方法一:建议不要直接使用commandbutton,先建一个commandbutton类的对象,声明一个实例变量is_clickedevent,在其clicked事件中写parent.Dynamic Event(is_clickedevent),创建后给is_clickedevent赋值。
方法二:窗口中的控件发生行为时会向窗口发送一个WM_COMMAND的消息(数据窗口的DDDW除外),你可以在窗口上加入一个pbm_command的事件,根据hwndchild(对象句柄)和notificationcode(存放通知代号,clicked为0)的不同写不同的代码。
另外,忘了提一下,pbdesigner的第一种方法应改为parent.Dynamic TriggerEvent(is_clickedevent),或PostEvent.