Triggering an event from another class?
-
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?
-
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?
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); -
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?
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 fromSystem.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) -
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?
Thank you guys. Did some snopping around and found no other way than you guys mentioned. Thank you...