Event Issue within Class Library [DLL]

Merchand

Well-known member
Joined
Dec 28, 2005
Messages
73
Location
USA Eastcoast
Programming Experience
10+
Sorry, if this is not the place to put a DLL question.

I have a modeless Messagebox class library that will display one of six messageboxes modelessly. I have a common event handler for the six test instantances and all six of the events are attached to the event handler using the "Handes" keyword. However, it seems like my events are not always raised using the common event hander method.

Is this a known issue? Or do I have to create an event hander for each of the six instances?

Any help is greatly appreciated. :)
 
You are getting confused between RAISING an event and HANDLING an event. The event is RAISED by the object itself internally. As long as the condition required to raise the event exists, the event will be raised. You cannot effect that from outside the object. What you are talking about is
HANDLING an event, which is done outside the object. If your object raises an event and you have a method marked as a handler for that event of that object then that method will be called. You can prevent events from travelling any further than a particular handler if it takes the appropriate arguments, like those event handlers that have an e.Handled or e.Cancel property. An event can be handled if and only if it is raised. If you're event handlers are not being called then it would imply that there is something wrong with your event implementation. Perhaps you should post the code you're using for each.
 
jmcilhinney,

Here is my common event handler that seemed to be a bit unstable...


PrivateSub CommonMsgBoxEventHandler(ByVal intButtonPressed AsInteger) Handles _
mOkOnlyMsgBox.ModelessMsgBoxUserResponse, _
mOkCancelMsgBox.ModelessMsgBoxUserResponse, _
mAbortRetryIgnoreMsgBox.ModelessMsgBoxUserResponse, _
mYesNoMsgBox.ModelessMsgBoxUserResponse, _
mYesNoCancelMsgBox.ModelessMsgBoxUserResponse, _
mRetryCancelMsgBox.ModelessMsgBoxUserResponse
Try
Me.lblButtonResponse.Text = "Button: " & CStr(intButtonPressed) & "Clicked"
Catch ex As Exception
Me.lblButtonResponse.Text = "Exception In CommonMsgBoxEventHandler Event - Error: " & ex.Message & CC.CrLf & _
"Source of Error: " & ex.Source
EndTry
EndSub

I checked my code over a few times and then found that I had been assigning a new ModelessMsgBox object to the same form variable instead of the three different variables. Some how this messed up the wired events. After I changed my three messagebox declarations it works good now.

Basically, I was doing this...

mYesNoMsgBox = New IDO_ModelessMsgBox.ModelessMsgBox
mYesNoMsgBox = New IDO_ModelessMsgBox.ModelessMsgBox
mYesNoMsgBox = New IDO_ModelessMsgBox.ModelessMsgBox

Instead of doing this...

mYesNoMsgBox = New IDO_ModelessMsgBox.ModelessMsgBox
mYesNoCancelMsgBox = New IDO_ModelessMsgBox.ModelessMsgBox
mRetryCancelMsgBox = New IDO_ModelessMsgBox.ModelessMsgBox

My declarations look like this...


Public WithEvents mYesNoMsgBox As IDO_ModelessMsgBox.ModelessMsgBox
Public WithEvents mYesNoCancelMsgBox As IDO_ModelessMsgBox.ModelessMsgBox
Public WithEvents mRetryCancelMsgBox As IDO_ModelessMsgBox.ModelessMsgBox

Anyway, I appreciate the guidance and help. I just have to get use to the wiring up of these events. :)
 
Back
Top