0

访问 vb.net 中声明的事件时遇到问题。

请仔细阅读下面的示例。(我已经修改了以下内容以使其不稳定,因为它是自定义控件开发之一的一部分)

Public Class Main
    Inherits ComboBox

    'Event handler for when an item check state changes.
    Public Event ItemCheck As ItemCheckEventHandler
    Private parentMainClass As Main
    Private cclb As controlClass

    Public Sub New(parentclass As Main)
        Me.parentMainClass = parentclass
        'Add a handler to notify our parent of ItemCheck events.
        AddHandler Me.cclb.ItemCheck, New System.Windows.Forms.ItemCheckEventHandler(AddressOf Me.cclb_ItemCheck)
    End Sub

    Private Sub cclb_ItemCheck(sender As Object, e As ItemCheckEventArgs)
        'If ccbParent.ItemCheck IsNot Nothing Then
            RaiseEvent parentMainClass.ItemCheck(sender,e)
        'End If
    End Sub

    Public Class controlClass
        Inherits CheckedListBox
    End Class
End Class

问题:RaiseEvent parentMainClass.ItemCheck(sender,e)此语句显示 - ItemCheck 事件不存在,即使它存在。

请指导。

谢谢你

4

2 回答 2

1

事件声明;

Public Event ItemCheck As ItemCheckEventHandler

应该;

Public Event ItemCheck(sender As Object, e As ItemCheckEventArgs)

错误告诉您的是它无法将事件与事件处理程序签名匹配。

于 2014-08-11T16:15:11.290 回答
0

从您的原始代码中,该行;

RaiseEvent parentMainClass.ItemCheck(sender, e)

应改为;

RaiseEvent ItemCheck(sender, e)

这会从当前实例引发 ItemCheck 事件。您似乎想要做的是在实例上引发事件,这有点不同。

于 2014-08-11T16:32:24.623 回答