none
vb.net 判断事件是否注册? RRS feed

  • 问题

  • 在C#中这样写没有错误:

                if (ComponentChanging != null) {
                    ComponentChangingEventArgs ce = new ComponentChangingEventArgs(component, member);
                    ComponentChanging(this, ce);
                }

    在vb.net中这样写出错:

            If ComponentChanging IsNot Nothing Then
                       Dim ce As New ComponentChangedEventArgs(component, member, oldValue, newValue)
                       RaiseEvent ComponentChanged(Me, ce)
            End If

    错误提示是说“If ComponentChanging IsNot Nothing Then”中ComponentChanging是事件应该使用RaiseEvent引发事件,怎么处理?

    严重性 代码 说明 项目 文件 禁止显示状态
    错误 BC32022 “Public Event ComponentAdding As ComponentEventHandler”是事件,不能直接调用。请使用“RaiseEvent”语句引发事件。

    2016年6月30日 6:58

答案

  • Hi,

    >>错误 BC32022 “Public Event ComponentAdding As ComponentEventHandler”是事件,不能直接调用。请使用“RaiseEvent”语句引发事件。

    你这个错误信息和当前使用的方法无关吧。你用的是ComponentChanged,错误提示的是ComponentAdding。

    你可以尝试用下面的代码替换报错的部分:

        Protected Event ComponentChanging As ComponentChangingEventHandler
        Private Sub Test()
            If ComponentChangingEvent <> Nothing Then
                Dim ce As New ComponentChangingEventArgs(Component, member)
                RaiseEvent ComponentChanging(Me.components, ce)
            End If
        End Sub

    参考链接:

    Testing Events for Nothing/Null (Doug Rothaus)

    Regards,

    Moonlight


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.





    2016年6月30日 8:52

全部回复

  • Hi,

    >>错误 BC32022 “Public Event ComponentAdding As ComponentEventHandler”是事件,不能直接调用。请使用“RaiseEvent”语句引发事件。

    你这个错误信息和当前使用的方法无关吧。你用的是ComponentChanged,错误提示的是ComponentAdding。

    你可以尝试用下面的代码替换报错的部分:

        Protected Event ComponentChanging As ComponentChangingEventHandler
        Private Sub Test()
            If ComponentChangingEvent <> Nothing Then
                Dim ce As New ComponentChangingEventArgs(Component, member)
                RaiseEvent ComponentChanging(Me.components, ce)
            End If
        End Sub

    参考链接:

    Testing Events for Nothing/Null (Doug Rothaus)

    Regards,

    Moonlight


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.





    2016年6月30日 8:52
  • 非常感谢,那个报错我贴错了,这错误搞的我头大,今天又遇到了这样的错误,太感谢你了.
    2016年8月26日 8:56
  • Hi,

    >>错误 BC32022 “Public Event ComponentAdding As ComponentEventHandler”是事件,不能直接调用。请使用“RaiseEvent”语句引发事件。

    你这个错误信息和当前使用的方法无关吧。你用的是ComponentChanged,错误提示的是ComponentAdding。

    你可以尝试用下面的代码替换报错的部分:

        Protected Event ComponentChanging As ComponentChangingEventHandler
        Private Sub Test()
            If ComponentChangingEvent <> Nothing Then
                Dim ce As New ComponentChangingEventArgs(Component, member)
                RaiseEvent ComponentChanging(Me.components, ce)
            End If
        End Sub

    参考链接:

    Testing Events for Nothing/Null (Doug Rothaus)

    Regards,

    Moonlight


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.





    非常感谢,那个报错我贴错了,这错误搞的我头大,今天又遇到了这样的错误,太感谢你了.
    2016年8月26日 9:02