Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Capturing Event

Capturing Event

Scheduled Pinned Locked Moved C#
tutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rull
    wrote on last edited by
    #1

    Is there is any way to handle events of different types by one function. For example I want to handle events of EventHandler type and my custom events with single function that have different number of parameters or have no parameters.

    G 1 Reply Last reply
    0
    • R rull

      Is there is any way to handle events of different types by one function. For example I want to handle events of EventHandler type and my custom events with single function that have different number of parameters or have no parameters.

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      You can add a handler to several different events, but if you need to determine where the event came from or what type of event it was, you have to check the values of the sender and eventargs parameters sent to the event handler. An event handler has to be declared with the exact parameters as the eventhandler delegate, e.g. with the sender and eventargs parameters. From the event handler you can then call any methods you wish in your code. --- b { font-weight: normal; }

      R 1 Reply Last reply
      0
      • G Guffa

        You can add a handler to several different events, but if you need to determine where the event came from or what type of event it was, you have to check the values of the sender and eventargs parameters sent to the event handler. An event handler has to be declared with the exact parameters as the eventhandler delegate, e.g. with the sender and eventargs parameters. From the event handler you can then call any methods you wish in your code. --- b { font-weight: normal; }

        R Offline
        R Offline
        rull
        wrote on last edited by
        #3

        The Problem is that I cannot use only eventhandler delegate. I am using Infragistics controls and For example i cannot add same function to Button.Click and Infragistics.Win.UltraWinEditors.UltraTextEditor.EditorButtonClick because it has type EditorButtonEventHandler. Maybe there is any way to handle such event using reflection?

        G 1 Reply Last reply
        0
        • R rull

          The Problem is that I cannot use only eventhandler delegate. I am using Infragistics controls and For example i cannot add same function to Button.Click and Infragistics.Win.UltraWinEditors.UltraTextEditor.EditorButtonClick because it has type EditorButtonEventHandler. Maybe there is any way to handle such event using reflection?

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          You need at least one event handler for each type of delegate. The event basically uses a reference to the handler to call it, and if the parameters that the handler accepts does not match the parameters that the event sends, you would mess upp the stack. Maybe you could add a event handler reference of the wrong type to the event using reflection, but that would probably just crash the application. --- b { font-weight: normal; }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups