我用代码建立了一个命令按钮,然后在在命令按钮里写代码。但是命令按钮不起作用
代码如下:
Private Sub command1_Click()
'添加文本
txt_top = txt_top + 600
txt_left = 200
Call addtxt(Me, txt_top, txt_left, 500, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 600, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 300, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 300, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 500, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 400, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 300, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 800, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 800, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 600, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 600, 300, 200, CStr("text" & txt_i))
End Sub
Private Sub Form_Load()
With Me
.Width = 15000
.Height = 6000
End With
txt_i = 1
cmd_i = 1
lab_i = 1
txt_left = 200
txt_top = 500
'添加文本
Call addtxt(Me, txt_top, txt_left, 500, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 600, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 300, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 300, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 500, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 400, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 300, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 800, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 800, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 600, 300, 200, CStr("text" & txt_i))
Call addtxt(Me, txt_top, txt_left, 500 + 600, 300, 200, CStr("text" & txt_i))
'添加命令按钮
Call addcmd(Me, 500, txt_left, 700, 300, 0, "插入", CStr("command" & cmd_i))
Call addcmd(Me, 1100, txt_left, 700, 300, 0, "删除", CStr("command" & cmd_i))
'添加标签
txt_left = 200
Call addlab(Me, txt_top - 400, txt_left, 700, 500, 200, "边坡点名称", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left - 100, 500 + 600, 300, 200, "边坡点桩号", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 300, 300, 200, "边坡点高程H", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 300, 300, 200, "切线长T", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 500, 300, 200, "半径R", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 400, 300, 200, "矢距E", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 300, 300, 200, "坡度I(%)", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 800, 300, 200, "坡度角", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500, 300, 200, "边坡角", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 800, 300, 200, "名称", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 600, 300, 200, "起点", CStr("label" & lab_i))
Call addlab(Me, txt_top - 400, txt_left, 500 + 600, 300, 200, "终点", CStr("label" & lab_i))
End Sub
模块:
Dim cmd As CommandButton
Public cmd_i As Integer
Function addcmd(c_frm As Form, c_top As Double, c_left As Double, c_width As Double, _
c_height As Double, c_n As Single, c_caption, c_name As String)
Set cmd = c_frm.Controls.Add("vb.commandbutton", c_name)
With cmd
.Top = c_top
.Left = c_left
.Width = c_width
.Height = c_height
.Caption = c_caption
.Visible = True
End With
cmd_i = cmd_i + 1
End Function