EventHandler

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matias Szulman

    #1

    EventHandler

    Hi!
    I need to know if an event (i.e. button1_click) has an eventhandler
    associated. Is this possible in c#?

    Thanks,

    Matias


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: EventHandler

    Matias,

    It isn't really possible. What you would have to do is keep a record of
    when the method is used for an event handler by overriding the event itself
    to store when a method is used and even then, you can't override types
    beyond your control to get that functionality.

    What exactly are you trying to do?


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Matias Szulman" <matias@nospam. orkon.com> wrote in message
    news:OjRvsiokDH A.3312@tk2msftn gp13.phx.gbl...[color=blue]
    > Hi!
    > I need to know if an event (i.e. button1_click) has an eventhandler
    > associated. Is this possible in c#?
    >
    > Thanks,
    >
    > Matias
    >
    >[/color]


    Comment

    • Matias Szulman

      #3
      Re: EventHandler

      I have a menu with menu items with different hierachies (for example, the
      menus within outlook express). Now some of them have eventhandlers for some
      events, but some don't (in OE, the MENU item in File does not have an
      eventhandler for the click event, while the MESSAGE item under MENU under
      FILE does have). I suppose it's hard to explain, but what I need to do is to
      create a treenode with a node for each menu item that has en eventhandler
      for the click event.

      Thanks in advance,

      Matias


      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: EventHandler

        Matias,
        In addition to Nicholas's comments.
        [color=blue]
        > I need to know if an event (i.e. button1_click) has an eventhandler
        > associated. Is this possible in c#?[/color]
        Are you asking does the Click event of the Button1 object have any handlers?

        Remember that an event in implemented in terms of a Delegate. If the
        Delegate is null there are no handlers, if the Delegate is not null there
        are handlers.

        http://msdn.microsoft.com/library/de...guidelines.asp

        If you are interested in the number of handlers, the Delegate has a
        GetInvocationLi st method that returns the list of methods associated with
        the delegate. Hence you can use GetInvocationLi st to get the number of
        handlers associated with the event.

        The problem you are going to run into, for classes that are not your own
        design (Button for example) the above Delegate is private.

        Hope this helps
        Jay


        "Matias Szulman" <matias@nospam. orkon.com> wrote in message
        news:OjRvsiokDH A.3312@tk2msftn gp13.phx.gbl...[color=blue]
        > Hi!
        > I need to know if an event (i.e. button1_click) has an eventhandler
        > associated. Is this possible in c#?
        >
        > Thanks,
        >
        > Matias
        >
        >[/color]


        Comment

        Working...