我已经定义了一个按钮,一个事件在按钮单击中引发了事件,所以我的问题是如何实现该事件
Public Event ClickEvent()
Private Sub Command1_Click()
RaiseEvent ClickEvent
End Sub
假设您发布的代码位于名为 Form1 的表单中。
创建一个新窗体 (Form2)。将此代码添加到 Form2:
'declare an object and tell vb you want to subscribe to the objects events
Private WithEvents Foo As Form1
Private Sub Form_Load()
'initialise the object
Set Foo = New Form1
'show the Form1 object which has the button on so we have something to click
Foo.Show
End Sub
'when the button is clicked this event is raised
Private Sub Foo_ClickEvent()
MsgBox "Click Event"
End Sub