Dim WithEvents oControl As CommandButton Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As LongPrivate Sub btn1_Click() ' vb-你控件的工程名 TextBox-你控件的类名 newText-生成后的控件名称 Set oControl = Controls.Add("VB.CommandButton", "newcmd", Me) With oControl
Dim WithEvents oControl As CommandButton
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As LongPrivate Sub btn1_Click() ' vb-你控件的工程名 TextBox-你控件的类名 newText-生成后的控件名称
Set oControl = Controls.Add("VB.CommandButton", "newcmd", Me) With oControl
.Visible = True '显示
.Left = 100
.Top = 100
.Width = 1800
.Caption = "这是你要的控件"
End With
End Sub
Private Sub oControl_click()
MsgBox "adf"
End Sub