Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
315
Unsubscribing from ToolClick Event
posted

 

Hello,

Within our application each of our Forms inherit from a base class called FormSecurity:

    public partial class frmMain : FormSecurity

    {

    ...

    }

We have a requirement that when our forms enter a "security mode" specific Events from the form will be unsubscribed from a method within FormSecurity (which doesn't have any knowledge of the subscribers to the Events), allowing us to instead subscribe to Events within FormSecurity. We've succesfully managed to do this for for an UltraButton in the following way:

        private void RemoveClickEvent(Control b)

        {

            PropertyInfo eventsProperty = typeof(Control).GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);

            EventHandlerList events = (EventHandlerList)eventsProperty.GetValue(b, null);

            FieldInfo eventKeyInfo = typeof (Control).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic);

 

            object eventKey = eventKeyInfo.GetValue(b);

            Delegate buttonClickEvent = events[eventKey];

            if (buttonClickEvent != null)

            {

                Delegate[] listOfAssignedHandlers = buttonClickEvent.GetInvocationList();

 

                foreach (Delegate handler in listOfAssignedHandlers)

                {

                    events.RemoveHandler(eventKey, handler);

 

                }

            }

    }

 

We've been attempting to implement this for the ToolClick Event on the UltraToolbarsManager control, but are unable to get this working as we cannot convert from 'Infragistics.Win.UltraWinToolbars.UltraToolbarsManager' to 'System.Windows.Forms.Control'.

 

Any clues to how we can get this working would be much appreciated.

Regards,

Dave