看了MSDN上面关于委托的示例,虽然能看懂,但是觉得有些麻烦,于是自己练习做了个最最最最简单的示例。。。
Public Class frmMain '声明一个委托类型 '然后我们就可以类似于 C/C++ 里面的函数指针一样去直接调用它了 Private Delegate Sub ShowMsg(ByVal sMsg As String) Private Sub Show_MSG_1(ByVal sMsg As String) MsgBox(sMsg,MsgBoxStyle.Information,"显示信息函数 1") End Sub Private Sub Show_MSG_2(ByVal sMsg As String) MsgBox(sMsg,MsgBoxStyle.Critical,"显示警告函数 2") End Sub Private Sub btnRun1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnRun1.Click Dim Show_Msg As ShowMsg = AddressOf Show_MSG_1 Show_Msg(TextBox1.Text) '或者用以下形式 'Show_Msg.Invoke(TextBox1.Text) End Sub Private Sub btnRun2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnRun2.Click Dim Show_Msg As ShowMsg = AddressOf Show_MSG_2 Show_Msg.Invoke(TextBox1.Text) '或者用以下形式 'Show_Msg(TextBox1.Text) End Sub End Class