我已经定义了一个按钮,一个事件正在按钮单击中引发事件,所以我的问题是如何实现该事件

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

关于events - 如何在 vb6 中实现一个事件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11219800/

10-17 00:33