Two instances of the same "raiseevent"

ALX

Well-known member
Joined
Nov 16, 2005
Messages
253
Location
Columbia, SC
Programming Experience
10+
I have "Form-A" that incorporates user control "UserControl-1".
Usercontrol-1 raises an event ("Event-X") that is handled by Form-A.
Now "Form-A" generates "Form-B" as a modal form (showdialog).
Form-B incorporates its own instance of UserControl-1.
Form-B has an event handler to handle the Event-X raised by it's instance of UserControl-1.
When Form-B's instance of UserControl-1 raises it's Event-X, neither Form-A or Form-B trap the event. I somehow expected Form-B to catch the event since it is a modal form and this particular Usercontrol-1 was instanciated by Form-B, but I would have been equally happy if both Form-A and Form-B trapped the event. I was suprised that neither form received the event.
...Anybody have a method for dealing with this ambiguity?
 
I apologize... I'm mostly brain dead ! :eek: I overlooked an important aspect of my situation here.
This is actually more complicated than I originally let on.
The UserControl1 is defined in Form-B as
VB.NET:
Friend WithEvents UserControl1 As New UserControlClass1
I'm trying to handle Event-X that UserControl1 raises in Form-B1 which inherits Form-B.
VB.NET:
Sub UpdateDisplay() Handles UserControl1.Event-X
I can trap Event-X if I place the handling sub in Form-B (the base class of the form that I want to handle it in). I need to define UserControl1 in Form-B because that form is also used by itself in another aspect of the program which utilizes UserControl1, but in that mode the usercontrol will never raise Event-X. Event-X is intended solely for use by Form-B1. So I guess I should rephrase my question...
How can I get an inheriting form to handle events raised by a user control that is defined in it's base class?
 
Make the base method Overridable, Overrides it in inherited class.
As usual the very basic beginner example come to our resque to see how this works between the base and inherited classes:
VB.NET:
[COLOR=blue]Sub testingOverriding()[/COLOR]
 MessageBox.Show("test1 base class:")
 Dim inst1 As New clsBase
 MessageBox.Show("test2 inherited class:")
 Dim inst2 As New clsInherited
End Sub
 
 
[COLOR=blue]Class clsBase[/COLOR]
 WithEvents eobj As New ObjectWithEvent
 Public Sub New()
  eobj.triggerevent()
 End Sub
 
 Overridable Sub evh() Handles eobj.tevent
  MessageBox.Show("event handled in base class")
 End Sub
 
End Class
 
 
[COLOR=blue]Class clsInherited[/COLOR]
[COLOR=blue]Inherits clsBase[/COLOR]
 
 Public Overrides Sub evh()
  MyBase.evh() 'comment out to not run default base handler
  MessageBox.Show("event handled in inherited class")
 End Sub
 
End Class
 
 
[COLOR=blue]Class ObjectWithEvent[/COLOR]
 Public Event tevent()
 Public Sub triggerevent()
  RaiseEvent tevent()
 End Sub
End Class
 
Back
Top