VB怎么给动态的按扭添加事件啊

来源:百度知道 编辑:UC知道 时间:2024/05/30 10:30:03
Private Sub Command1_Click()
Dim command As CommandButton
Set CommandButton = Controls.Add("vb.CommandButton", "Cmd")
With CommandButton
.Left = 100
.Top = 100
.Width = 2000
.Height = 375
.Caption = Time
.Visible = True
End With
End Sub
怎么给CMD控件加事件啊

建一个Command1。
代码如下。
===================
Dim WithEvents cmd As CommandButton '这一句特别重要
Private Sub Command1_Click()
Set cmd = Controls.Add("vb.commandbutton", "cmd1")
cmd.Visible = True
End Sub
Private Sub cmd_click() '动态按钮事件
MsgBox ""
End Sub