标签:color bin std test button click get and 调用
Dim DelegetSub1 As testDelegetSub = New testDelegetSub(AddressOf testDelegateSub2) Dim DelegetSub2 As testDelegetSub = New testDelegetSub(AddressOf testDelegateSub3) Dim DelegetSub3 As testDelegetSub = System.Delegate.Combine(DelegetSub1, DelegetSub2)
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click DelegetSub3() ‘先调用DelegetSub1、DelegetSub2 DelegetSub3 = System.Delegate.Remove(DelegetSub3, DelegetSub1) ‘移除DelegetSub3 中的DelegetSub1 再赋值给DelegetSub3 DelegetSub3() ‘其实是只调用DelegetSub2 DelegetSub3 = System.Delegate.Remove(DelegetSub3, DelegetSub1) ‘已经移除过DelegetSub1 但不会报错 DelegetSub3 = System.Delegate.Remove(DelegetSub3, DelegetSub2) If DelegetSub3 Is Nothing Then MessageBox.Show("DelegetSub3此委托为空不能调用") Else DelegetSub3() ‘ DelegetSub3里面为空时调用会报错 所有要先判断 End If End Sub
Private Sub testDelegateSub2() MessageBox.Show("委托测试成功111!!!") Me.Text = "委托测试成功111!!!" End Sub Private Sub testDelegateSub3() MessageBox.Show("委托测试成功222!!!") End Sub
标签:color bin std test button click get and 调用
原文地址:https://www.cnblogs.com/bowang/p/14944903.html