新建一个Activex控件工程,添加两个按钮。 Private Sub UserControl11_Botton1Click() MsgBox "你按下了第一个按钮" End SubPrivate Sub UserControl11_Botton2Click() MsgBox "你按下了第二个按钮" End Sub 生成控件。 新建一标准工程。 添加生成的控件, Private Sub UserControl11_Botton1Click() MsgBox "你按下了第一个按钮" End SubPrivate Sub UserControl11_Botton2Click() MsgBox "你按下了第二个按钮" End Sub Botton1Click()和Botton2Click()就是自己添加的事件 这只是最简单的。MSDN上有更详细的说明。
参考: http://www.applevb.com/art/dyn_control.txt
Private WithEvents mycontrol As Timer'你可以换成你的控件名 as 你的控件名 Private Sub Form_Load() mycontrol.Interval = 1000 End SubPrivate Sub mycontrol_Timer() Debug.Print Now End Sub
Private Sub UserControl11_Botton1Click()
MsgBox "你按下了第一个按钮"
End SubPrivate Sub UserControl11_Botton2Click()
MsgBox "你按下了第二个按钮"
End Sub
生成控件。
新建一标准工程。
添加生成的控件,
Private Sub UserControl11_Botton1Click()
MsgBox "你按下了第一个按钮"
End SubPrivate Sub UserControl11_Botton2Click()
MsgBox "你按下了第二个按钮"
End Sub
Botton1Click()和Botton2Click()就是自己添加的事件
这只是最简单的。MSDN上有更详细的说明。
http://www.applevb.com/art/dyn_control.txt
Private Sub Form_Load()
mycontrol.Interval = 1000
End SubPrivate Sub mycontrol_Timer()
Debug.Print Now
End Sub
http://www.jxxx.ykedu.net/qsgjx/vbprograms/form/actaddctls.zip