VB通过Controls.Add添加的控件怎么点击?

Private Sub Form_Load()
Set playyy = Controls.Add("VB.CommandButton", "playyy", Me)
With playyy
.Visible = True
.Top = 100 + 500
.Left = 3000
.Caption = "Test"
End With
End Sub

Private Sub playyy_Click()
MsgBox "haha"
End Sub
点击生成的按纽没反应,哪错了?
已自己解决,前面定义的时候加上 withEvents
Dim WithEvents playyy As CommandButton

第1个回答  2015-02-05
Private WithEvents cmdObject As CommandButton

Private Sub Form_Load()
Set cmdObject = Form1.Controls.Add("VB.CommandButton", "cmdOne")
cmdObject.Visible = True
cmdObject.Caption = "Dynamic CommandButton"
End Sub

Private Sub cmdObject_Click()
Print "This is a dynamically added control"
End Sub本回答被网友采纳
第2个回答  2015-02-05
CommandButton 控件的 ProgID 是 VB。
相似回答