'定義委派
Public Delegate Sub sayHello(ByVal thing As String)

Public Class HelloWorld
    Private _msg As String
    '事件
    Public Event MyEvent As sayHello
    '屬性
    Public Property Msg() As String
        Get
            Return _msg
        End Get
        Set(ByVal value As String)
            _msg = value
        End Set
    End Property


    '引發事件的 method
    Public Sub REmethod(ByVal s As String)
        '引發事件
        RaiseEvent MyEvent(s)
    End Sub
End Class

Module TestEvent

    Public Sub Main()
        '建構物件
        Dim hello As New HelloWorld()
        '建立事件程序
        '管理員建立
        Dim handler As New sayHello(AddressOf HelloWorld)
        '聽物件的事件
        AddHandler hello.MyEvent, handler
        '引發
        hello.REmethod("cloud")
    End Sub

    '事件程序
    Private Sub HelloWorld(ByVal s As String)
        System.Console.WriteLine(s + " 歡迎光臨!!")
    End Sub
End Module
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 colud77 的頭像
    colud77

    I-Cloud程式攻略

    colud77 發表在 痞客邦 留言(1) 人氣()