Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hook up an event to an event in VB.Net

Is it possible to hook up an event to another event in VB8? I have this code in C#...

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

And am trying to convert it into VB8, but can't get it to work..

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

Thanks!

like image 634
devghost Avatar asked Oct 15 '22 12:10

devghost


1 Answers

You just need to pass the name of the event handler routine after 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
like image 184
Carl Rippon Avatar answered Nov 01 '22 12:11

Carl Rippon