Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My question refers to the following Thread : http://www.codeproject.com/Questions/992555/Event-outside-of-a-collection?arn=23

I want to "override" an Event from a derived class - for example from a Forms-Control.

My actual State is, that the overriding (performed by the Command "Shadows") is working when I use the Handler of this Control directly.
Is the Control a member of a Collection it is only working with such Events which I have created by myself - if I try to use the overridden Event it isn't working. I suppose that the Collection uses the Event from the Base-Class.
Is that possible ?
And if "Yes" - what could I do ?
Posted

1 solution

With the help of Sergey (-SA), in another question with a complete different topic, I found the Solution by myself.
It must be done with Reflection and calling the Event-method in the Parent-Control.

Here is a code-snippet which shows how it could be done :
VB
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click

     Dim onclick1 As System.Reflection.MethodInfo = Button1.[GetType]().GetMethod("OnClick", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
     onclick1.Invoke(Button1, New Object() {New EventArgs()})

 End Sub


In this case the Button2 uses the method inside the Button1.
The Event is raised by Button1 and not by Button2.

At this place again my thank to Sergey for his assistance and inspiration ... :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900