如何将事件与VB.Net中的事件挂钩

时间:2009-11-10 08:55:24

标签: vb.net event-handling

是否可以将事件与VB8中的另一个事件挂钩? 我在C#中有这段代码......

public event ShowAboutDialog = delegate {};
private void hookupEvents() {
  myButton.Click += ShowAboutDialog;
}

我正在尝试将其转换为VB8,但无法让它工作..

Public Event ShowAboutDialog As EventHandler
Private Sub HookupEvents()
    AddHandler AboutMenuItem.Click, AddressOf ShowAboutDialog
End Sub

谢谢!

1 个答案:

答案 0 :(得分:4)

您只需要在 AddressOf

之后传递事件处理程序例程的名称
Private Sub HookupEvents()
    AddHandler AboutMenuItem.Click, AddressOf ShowAboutDialog
End Sub

Public Sub ShowAboutDialog(ByVal sender As Object, ByVal e As System.EventArgs)

End Sub