> Carl,
> Within the Shared class you can define Shared event and that event
[quoted text clipped - 25 lines]
>
> - Show quoted text -
Maybe if I showed some test code the question would make more sense.
I'm invoking a shared method here:
MenuManager1.TestIt()
This event is executing a method which some some work and raises and
event here:
Public Class MenuManager1
Inherits System.Object
Public Shared Event Start(ByVal y As Int32)
Public Shared Sub TestIt()
RaiseEvent Start(123)
End Sub
End Class
I want the MySender_Start() event handler method to fire when the
RaiseEvent is invoked. The problem is that this is not happening. The
testIt event just finishes executong withou firing MySender_Start() .
No error occurs.
Public Class MyForm
Private WithEvents MySender As MenuManager1
Private Sub MySender_Start(ByVal y As Int32) Handles MySender.Start
Dim x As Int32
x = 1
End Sub
End Class
What am I missing here?
Thanks again
Carl
zacks@construction-imaging.com - 21 May 2008 21:49 GMT
> > Carl,
> > Within the Shared class you can define Shared event and that event
[quoted text clipped - 68 lines]
>
> What am I missing here?
The event handler in the form class needs to be Public, not private,
since it is being invoked from a different class object.
Steve Gerrard - 22 May 2008 06:35 GMT
> I want the MySender_Start() event handler method to fire when the
> RaiseEvent is invoked. The problem is that this is not happening. The
[quoted text clipped - 16 lines]
>
> What am I missing here?
Your missing that MySender would be an instance, not the shared class itself,
and that it is Nothing, since you never create an instance.
You want to handle MenuManager1.Start itself, something like this:
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
AddHandler MenuManager1.Start, AddressOf MyStartHandler
End Sub
Private Sub MyStartHandler(ByVal y As Integer)
MsgBox(y.ToString)
End Sub
SetonSoftware - 22 May 2008 14:38 GMT
> > I want the MySender_Start() event handler method to fire when the
> > RaiseEvent is invoked. The problem is that this is not happening. The
[quoted text clipped - 34 lines]
>
> - Show quoted text -
Many thanks. And for the benefit of others here is the full working
solution:
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AddHandler MenuManager1.Start, AddressOf MySender_Start
MenuManager1.TestIt()
End Sub
Public Sub MySender_Start(ByVal y As Int32)
Dim x As Int32
x = 1
End Sub
Public Class MenuManager1
Inherits System.Object
Public Shared Event Start(ByVal y As Int32)
Public Shared Sub TestIt()
RaiseEvent Start(123)
End Sub
End Class
zacks@construction-imaging.com - 22 May 2008 20:36 GMT
> > > I want the MySender_Start() event handler method to fire when the
> > > RaiseEvent is invoked. The problem is that this is not happening. The
[quoted text clipped - 65 lines]
>
> End Class
You didn't have to change from defining the event hander with the
HANDLES keyword to an ADDHANDLER statement. Either way will work, it's
your own preference.