下面是我写的一个关于委托最简单的例子:
Form1是指一个窗体,TextBox1是指一个TextBox控件
Private Function HelloWorld() As String
Return "Hello world"
End Function
Delegate Function myMethodDelegate() As String
Dim MyDelegate As New myMethodDelegate(AddressOf HelloWorld)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TextBox1.Text = MyDelegate()
End Sub
Return "Hello world"
End Function
Delegate Function myMethodDelegate() As String
Dim MyDelegate As New myMethodDelegate(AddressOf HelloWorld)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TextBox1.Text = MyDelegate()
End Sub