如何用命令创建一个控件,并在些控件下写代码
如何用命令创建一个控件,并在些控件下写代码
如何用命令创建一个控件,并在此控件下写代码
如何用命令创建一个控件,并在此控件下写代码
frmMyForm = CREATEOBJECT('Form') && 创建表单 frmMyForm.Closable = .F. && 禁止 Control 菜单框 frmMyForm.AddObject('cmdCommand1','cmdMyCmndBtn') && 添加命令按钮 frmMyForm.AddObject('opgOptionGroup1','opgMyOptGrp') && 添加选项按钮组 frmMyForm.AddObject('shpCircle1','shpMyCircle') && 添加圆形 frmMyForm.AddObject('shpEllipse1','shpMyEllipse') && 添加椭圆形 frmMyForm.AddObject('shpSquare','shpMySquare') && 添加正方形 frmMyForm.cmdCommand1.Visible =.T. && "退出"命令按钮可见 frmMyForm.opgOptionGroup1.Buttons(1).Caption = "\<Circle" frmMyForm.opgOptionGroup1.Buttons(2).Caption = "\<Ellipse" frmMyForm.opgOptionGroup1.Buttons(3).Caption = "\<Square" frmMyForm.opgOptionGroup1.SetAll("Width", 100) && 设置选项按钮组宽度 frmMyForm.opgOptionGroup1.Visible = .T. && 选项按钮组可见 frmMyForm.opgOptionGroup1.Click && 显示圆形 frmMyForm.SHOW && 显示表单 READ EVENTS && 开始事件处理 DEFINE CLASS opgMyOptGrp AS OptionGroup && 创建选项按钮组 ButtonCount = 3 && 三个选项按钮 Top = 10 Left = 10 Height = 75 Width = 100 PROCEDURE Click ThisForm.shpCircle1.Visible = .F. && 隐藏圆形 ThisForm.shpEllipse1.Visible = .F. && 隐藏椭圆形 ThisForm.shpSquare.Visible = .F. && 隐藏正方形 DO CASE CASE ThisForm.opgOptionGroup1.Value = 1 ThisForm.shpCircle1.Visible = .T. && 显示圆形 CASE ThisForm.opgOptionGroup1.Value = 2 ThisForm.shpEllipse1.Visible = .T. && 显示椭圆形 CASE ThisForm.opgOptionGroup1.Value = 3 ThisForm.shpSquare.Visible = .T. && 显示正方形 ENDCASE ENDDEFINE DEFINE CLASS cmdMyCmndBtn AS CommandButton && 创建命令按钮 Caption = '\<Quit' && 命令按钮的标题 Cancel = .T. && 默认的取消命令按钮 (Esc) Left = 125 && 命令按钮所在列 Top = 210 && 命令按钮所在行 Height = 25 && 命令按钮高度 PROCEDURE Click CLEAR EVENTS && 停止事件处理, 关闭表单 ENDDEFINE DEFINE CLASS shpMyCircle AS SHAPE && 创建一个圆形 Top = 10 Left = 200 Width = 100 Height = 100 Curvature = 99 BackColor = RGB(255,0,0) && 红色 ENDDEFINE DEFINE CLASS shpMyEllipse AS SHAPE && 创建一个椭圆形 Top = 35 Left = 200 Width = 100 Height = 50 Curvature = 99 BackColor = RGB(0,128,0) && 绿色 ENDDEFINE DEFINE CLASS shpMySquare AS SHAPE && 创建一个正方形 Top = 10 Left = 200 Width = 100 Height = 100 Curvature = 0 BackColor = RGB(0,0,255) && 蓝色 ENDDEFINE
PUBLIC oform1 oform1=NEWOBJECT("form1") oform1.Show RETURN ************************************************** *-- Form: form1 *-- ParentClass: form *-- BaseClass: form *-- 时间戳: 01/15/13 02:34:05 PM * DEFINE CLASS form1 AS form Height = 336 Width = 498 DoCreate = .T. AutoCenter = .T. Caption = "Form1" *-- 指定包含在集合中的成员数目。 count = 0 Name = "form1" ADD OBJECT cmdcreate AS commandbutton WITH ; Top = 276, ; Left = 216, ; Height = 25, ; Width = 60, ; Caption = "创建控件", ; Name = "cmdCreate" PROCEDURE showmsg local loObj loObj = thisform.ActiveControl MESSAGEBOX("控件"+loObj.name+"被单击!") ENDPROC PROCEDURE count_access *To do: 为 Access 方法程序修改此例程 this.count = this.count +1 RETURN THIS.count ENDPROC PROCEDURE cmdcreate.Click local lnCount,lcCmdName lnCount = thisform.count lcCmdName = "command"+TRANSFORM(lnCount) thisform.AddObject(lcCmdName,"commandbutton") thisform.&lcCmdName..visible = .T. thisform.&lcCmdName..height = 24 thisform.&lcCmdName..left = (thisform.Width -thisform.&lcCmdName..Width)/2 thisform.&lcCmdName..top = lnCount*30 BINDEVENT(thisform.&lcCmdName,"click",thisform,"showmsg") ENDPROC ENDDEFINE * *-- EndDefine: form1 **************************************************以上代码是用命令添加控件后,将控件的事件绑定到表单的自定义方法。