博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
VB.NET代理事件
阅读量:6432 次
发布时间:2019-06-23

本文共 1418 字,大约阅读时间需要 4 分钟。

单一代理:

Module Module1

    Public Delegate Sub basicdeleg(ByVal st As String)
    Sub Main()
        Dim d1 As New deleg()
        Dim DG1, DG2 As basicdeleg
        DG1 = AddressOf d1.eventchar
        DG2 = AddressOf d1.eventmess
        DG1("this char console message !")
        DG2("THIS CHAR WILL SHOW ON MESSAGE BOX !")

    End Sub

    Public Class deleg
        Public Sub eventchar(ByVal st As String)
            Console.WriteLine("delegate sucessfully !" & st)
        End Sub
        Public Sub eventmess(ByVal st As String)
            MsgBox("delegate successfully ! " & st)
        End Sub
    End Class
End Module

一对多代理:

Module Module1

    Sub Main()

        Dim DC1 As New DelegateCenter()
        DC1.DelReg(AddressOf delevent1, True)
        DC1.DelReg(AddressOf delevent2, False)
        DC1.DelReg(AddressOf delevent3, True)
        DC1.exefunc(300)
        Console.ReadLine()

    End Sub

    Public Sub delevent1(ByVal st As String)

        Console.WriteLine("delegate event 1 will be start !")
    End Sub

    Public Sub delevent2(ByVal st As String)

        Console.WriteLine("delegate event 2 will be start !")
    End Sub

    Public Sub delevent3(ByVal st As String)

        Console.WriteLine("delegate event 3 will be start !")
    End Sub

    Public Class DelegateCenter

        Public Delegate Sub INRegFunc(ByVal st As String)
        Private m_customer As INRegFunc
        Public Sub DelReg(ByVal DG1 As INRegFunc, ByVal decrib As Boolean)
            If decrib Then
                m_customer = CType(System.Delegate.Combine(m_customer, DG1), INRegFunc)
            End If
        End Sub

        Public Sub exefunc(ByVal st As String)

            m_customer("run successfully ...")
        End Sub
    End Class
End Module

 

转载地址:http://oixga.baihongyu.com/

你可能感兴趣的文章
maven安装第三方包
查看>>
Python初识
查看>>
获取AJAX加载的内容
查看>>
Git单人本地仓库操作
查看>>
orocos_kdl学习(一):坐标系变换
查看>>
两步完成利用procdump64+mimikatz获取win用户密码
查看>>
Mac 的命令行配置字体颜色
查看>>
linux后台执行程序
查看>>
剑指offer---二叉搜索树的后序遍历序列
查看>>
Bit Operation妙解算法题
查看>>
VLC Play in web
查看>>
详解PNG文件结构
查看>>
Statistics与Machine Learning有什么区别
查看>>
python 记录
查看>>
Silverlight 鼠标双击 事件
查看>>
Actionscript通过构造自定义事件和方法,谈谈可选参数的问题
查看>>
递归与尾递归总结
查看>>
笔试题错题集
查看>>
ssm+maven+pageHelper搭建maven项目实现快速分页
查看>>
UIImagePickerController, memory warning
查看>>