How do I invalidate an Event

  • Thread starter Thread starter John Taylor
  • Start date Start date
J

John Taylor

How do I invalidate the click event of a sub classed
button from the parent class.

I've created a button usercontrol for my windows form, and
in the click event in the parent if got a confirmation
msgbox. If the user pressed 'cancel', I don't want
the 'click' event of the child control to fire.

Please help, I've sent 2 days on this now and my brain is
hurting.

I know its something to do with inheritance but can't work
out what.

please help
John
 
MyUserControlClass - the UC class
userControlInstance - the instance in the form
MyUserControlClass_Click - the handler method for the Click event

System.Reflection.EventInfo UserControlEventInfo = (typeof(MyUserControlClass)).GetEvent("Click");
System.Reflection.MethodInfo removeMethod = UserControlEventInfo.GetRemoveMethod();
removeMethod.Invoke(userControlInstance,new Object[] {new System.EventHandler(userControlInstance.MyUserControlClass_Click)});


but for that I need to make public in MyUserControlClass the delegated method MyUserControlClass_Click because the isolation level make them invisible.
probably with a more complex invoke you won't need this.
 
Thank you!
Very much appreciated!
John
-----Original Message-----
MyUserControlClass - the UC class
userControlInstance - the instance in the form
MyUserControlClass_Click - the handler method for the Click event

System.Reflection.EventInfo UserControlEventInfo = (typeof (MyUserControlClass)).GetEvent("Click");
System.Reflection.MethodInfo removeMethod = UserControlEventInfo.GetRemoveMethod();
removeMethod.Invoke(userControlInstance,new Object[] {new System.EventHandler
(userControlInstance.MyUserControlClass_Click)});


but for that I need to make public in MyUserControlClass
the delegated method MyUserControlClass_Click because the
isolation level make them invisible.
 
Can any of you C# ninjas convert the solution into vb?

If not cool, i'll go the msdn route.
Thamks again
John
-----Original Message-----
Thank you!
Very much appreciated!
John
-----Original Message-----
MyUserControlClass - the UC class
userControlInstance - the instance in the form
MyUserControlClass_Click - the handler method for the Click event

System.Reflection.EventInfo UserControlEventInfo =
(typeof
(MyUserControlClass)).GetEvent("Click");
System.Reflection.MethodInfo removeMethod = UserControlEventInfo.GetRemoveMethod();
removeMethod.Invoke(userControlInstance,new Object[]
{new
System.EventHandler
(userControlInstance.MyUserControlClass_Click)});


but for that I need to make public in MyUserControlClass
the delegated method MyUserControlClass_Click because the
isolation level make them invisible.
probably with a more complex invoke you won't need this.
.
 
Back
Top