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. Triggering an event from another class?

Triggering an event from another class?

Scheduled Pinned Locked Moved C#
databasedesignhelpquestion
4 Posts 3 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.
  • F Offline
    F Offline
    faheemnadeem
    wrote on last edited by
    #1

    Hi, Scenario: I have many user components added to a form. I wish to do some information reporting from each user control to a centralized destination, where many form can subscribe and acquire the information. I have a class named MiscFunctions, contains an informationEvent handler which each forms subscribes too rather than subscribing to each UI component. I want to trigger that event present in Miscfunctions class from my UI components with some arguments, and all my forms subscribing to an event in miscfunctions to listen it. Any help please?

    S D F 3 Replies Last reply
    0
    • F faheemnadeem

      Hi, Scenario: I have many user components added to a form. I wish to do some information reporting from each user control to a centralized destination, where many form can subscribe and acquire the information. I have a class named MiscFunctions, contains an informationEvent handler which each forms subscribes too rather than subscribing to each UI component. I want to trigger that event present in Miscfunctions class from my UI components with some arguments, and all my forms subscribing to an event in miscfunctions to listen it. Any help please?

      S Offline
      S Offline
      Samuel Cherinet
      wrote on last edited by
      #2

      I assume you are using static Eventhandlers on your Miscfunction ... what you need is another static method that is used to raise the event when ever you want, hope I got your question

      //this goes in your miscfuncition class
      static event EventHandler commonHandler;
      static void raiseCommonHandler(object sender, EventArgs e)
      {
      if (commonHandler != null)
      commonHandler(sender, e);
      }

      //component class
      //to raise the event
      MiscFunction.raiseCommonHandler(new object(),null);

      1 Reply Last reply
      0
      • F faheemnadeem

        Hi, Scenario: I have many user components added to a form. I wish to do some information reporting from each user control to a centralized destination, where many form can subscribe and acquire the information. I have a class named MiscFunctions, contains an informationEvent handler which each forms subscribes too rather than subscribing to each UI component. I want to trigger that event present in Miscfunctions class from my UI components with some arguments, and all my forms subscribing to an event in miscfunctions to listen it. Any help please?

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        You need to create and call a method in your MiscFunctions instance (or static class) that raises your custom event passing an instance of your own event args class (derived from System.EventArgs) as a parameter.

        Dave

        If this helped, please vote & accept answer!

        Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

        1 Reply Last reply
        0
        • F faheemnadeem

          Hi, Scenario: I have many user components added to a form. I wish to do some information reporting from each user control to a centralized destination, where many form can subscribe and acquire the information. I have a class named MiscFunctions, contains an informationEvent handler which each forms subscribes too rather than subscribing to each UI component. I want to trigger that event present in Miscfunctions class from my UI components with some arguments, and all my forms subscribing to an event in miscfunctions to listen it. Any help please?

          F Offline
          F Offline
          faheemnadeem
          wrote on last edited by
          #4

          Thank you guys. Did some snopping around and found no other way than you guys mentioned. Thank you...

          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