如何在vb6中实现事件?

时间:2012-06-27 05:13:36

标签: events vb6

我已经定义了一个按钮,一个事件是按钮点击提升事件所以我的问题是如何实现该事件

Public Event ClickEvent()

Private Sub Command1_Click()
    RaiseEvent ClickEvent
End Sub

1 个答案:

答案 0 :(得分:9)

假设您发布的代码位于名为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