vb编程中怎么直接在代码中生成一个按钮?

2024-12-23 05:39:21
推荐回答(2个)
回答1:

Private Sub Command1_Click()
Dim cmd1 As Control
Set cmd1 = Me.Controls.Add("vb.commandbutton", "cmd1", Me)
With cmd1
.Caption = "cmd1"
.Left = 100
.Top = 100
cmd1.Visible = True
End With
End Sub

还可以用控件数组,像1楼说的那样!!

回答2:

首先将command1的index属性设置为0
Dim i As Integer
Private Sub Command1_Click(Index As Integer)
i = i + 1
Load Command1(i)
Command1(i).Top = 0
Command1(i).Visible = True
End Sub
上面的方法在vb6.0下是可以的,我刚试过,