Public Class Form1 'こちらは Handles 句付きのイベントハンドラーです Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click 'その中で、Button2 の Click イベントを AddHandler します AddHandler Me.Button2.Click, AddressOf Me.Button2_Click End Sub
'こちらは Handles 句無しにしています Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) MsgBox("Button2") End Sub End Class
Private Results(9) As 処理結果クラス Private Sub Completed0(sender As Object, e As HogeEventArgs) Results(0) = e.処理結果 End Sub Private Sub Completed1(sender As Object, e As HogeEventArgs) Results(1) = e.処理結果 End Sub Private Sub Completed9(sender As Object, e As HogeEventArgs) Results(9) = e.処理結果 End Sub
Private proc(9) As 画像処理クラス Private Results(9) As 処理結果クラス Private Sub Form1_Load(… proc(0) = New 画像処理クラス(…) proc(1) = New 画像処理クラス(…) proc(9) = New 画像処理クラス(…) Array.ForEach(proc, Sub(p) AddHandler p.Completed, AddressOf Me.Completed) End Sub Private Sub Completed(sender As Object, e As HogeEventArgs) Dim index As Integer = Array.IndexOf(proc, sender) Results(index) = e.処理結果 End Sub