luni, 25 august 2014

AddHandler Visual Basic Example

AddHandler link an event with an event handler at run time.

Example:

1. Add event to an object

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgsHandles MyBase.Load
        Dim Obj As New Class1
        ' Associate an event handler with an event
        AddHandler Obj.myEvent, AddressOf EvHandler
        Obj.Class1Event()
    End Sub

    Sub EvHandler()
        ' Handle the event
        MsgBox("EvHandler")
    End Sub

    Public Class Class1
        Public Event myEvent()
        Public Sub Class1Event()
            RaiseEvent myEvent()
        End Sub
    End Class

End Class

Niciun comentariu:

Trimiteți un comentariu