[英]Facing an issue while accessing declared event in vb.net
Facing an issue while accessing declared event in vb.net. 在vb.net中访问声明的事件时遇到问题。
Please go thorough below example. 请仔细阅读以下示例。 (I have modified below stuff to make understable as it is part of one of custom control development)
(我修改了以下内容,使其变得不稳定,因为它是自定义控件开发之一)
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
Problem: RaiseEvent parentMainClass.ItemCheck(sender,e)
this statement shows - ItemCheck event not exists even though it is existed. 问题:此语句显示
RaiseEvent parentMainClass.ItemCheck(sender,e)
-即使存在ItemCheck事件也不存在。
Please guide. 请指导。
Thank You 谢谢
The event declaration; 事件声明;
Public Event ItemCheck As ItemCheckEventHandler
Should be; 应该;
Public Event ItemCheck(sender As Object, e As ItemCheckEventArgs)
What the error is telling you is that it cannot match up the event to the event handler signature. 该错误告诉您的是,它无法将事件与事件处理程序签名匹配。
From your original code, the line; 从您的原始代码开始;
RaiseEvent parentMainClass.ItemCheck(sender, e)
should be changed to; 应该改为
RaiseEvent ItemCheck(sender, e)
This raises the ItemCheck event from the current instance. 这从当前实例引发ItemCheck事件。 What you seem to be wanting to do is to raise the event on the parent instance, which is a bit different.
您似乎想要做的是在父实例上引发事件,这有点不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.