gpt4 book ai didi

vb.net - VB.net 中事件的显式添加/删除

转载 作者:行者123 更新时间:2023-12-03 00:33:48 24 4
gpt4 key购买 nike

在 C# 中,您可以在订阅/取消订阅事件时定义显式添加/删除代码。

这在 VB.net 中可能吗?

最佳答案

Imports System.Runtime.CompilerServices
...
Private propchanged As PropertyChangedEventHandler

Public Custom Event PropertyChanged As PropertyChangedEventHandler

<MethodImpl(MethodImplOptions.Synchronized)> _
AddHandler(ByVal value As PropertyChangedEventHandler)
propchanged = DirectCast([Delegate].Combine(propchanged, value), PropertyChangedEventHandler)
End AddHandler

<MethodImpl(MethodImplOptions.Synchronized)> _
RemoveHandler(ByVal value As PropertyChangedEventHandler)
propchanged = DirectCast([Delegate].Remove(propchanged, value), PropertyChangedEventHandler)
End RemoveHandler

RaiseEvent(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs)
Dim handler = propchanged
If handler IsNot Nothing Then handler(sender, e)
End RaiseEvent
End Event

关于vb.net - VB.net 中事件的显式添加/删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4647732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com