Centralised Events
-
I come from a Delphi background, (just learning the C# and .Net). In Delphi, event handlers can be centralised using an action list. In this way I can assign the same event handler to as many cotrols as I like. In addition I can manage the event handlers by iterating thru the list and enabling as I wish and also setting various other properties of the action. My question is how can this be done in C#? Thank-you for your kind help Luke :)
-
I come from a Delphi background, (just learning the C# and .Net). In Delphi, event handlers can be centralised using an action list. In this way I can assign the same event handler to as many cotrols as I like. In addition I can manage the event handlers by iterating thru the list and enabling as I wish and also setting various other properties of the action. My question is how can this be done in C#? Thank-you for your kind help Luke :)
Well, I'll take a stab at this. 1. I believe in C# you can assign the same event handler to multiple events. Just add the event function to the event handler, which, with regards to your question, can easily be done as part of the member of the control. 2. Multiple events can be assigned to the same handler. This is a nice feature, though I've never used it yet myself. 3. As far as iterating through a list of event handlers and enabling/disabling them, I don't believe this can be done (I don't think C# has a master event collection, but I could be wrong). This is why I personally vector everything through an event manager class, which not only lets me trace all events, but as you said, I can enable/disable events. I can also specify whether the event is run in-line or as a separate thread, and I've recently added the ability to do run time binding of events to functions based on the function assembly, class, and name, using C#'s reflection class. You said ...and also setting various other properties of the action. I'm curious--what other kinds of properties? Marc
-
Well, I'll take a stab at this. 1. I believe in C# you can assign the same event handler to multiple events. Just add the event function to the event handler, which, with regards to your question, can easily be done as part of the member of the control. 2. Multiple events can be assigned to the same handler. This is a nice feature, though I've never used it yet myself. 3. As far as iterating through a list of event handlers and enabling/disabling them, I don't believe this can be done (I don't think C# has a master event collection, but I could be wrong). This is why I personally vector everything through an event manager class, which not only lets me trace all events, but as you said, I can enable/disable events. I can also specify whether the event is run in-line or as a separate thread, and I've recently added the ability to do run time binding of events to functions based on the function assembly, class, and name, using C#'s reflection class. You said ...and also setting various other properties of the action. I'm curious--what other kinds of properties? Marc
Marc Clifton wrote: 3. As far as iterating through a list of event handlers and enabling/disabling them, I don't believe this can be done (I don't think C# has a master event collection, but I could be wrong). This is why I personally vector everything through an event manager class, which not only lets me trace all events, but as you said, I can enable/disable events. I can also specify whether the event is run in-line or as a separate thread, and I've recently added the ability to do run time binding of events to functions based on the function assembly, class, and name, using C#'s reflection class. Article please!!!!:-D
-
I come from a Delphi background, (just learning the C# and .Net). In Delphi, event handlers can be centralised using an action list. In this way I can assign the same event handler to as many cotrols as I like. In addition I can manage the event handlers by iterating thru the list and enabling as I wish and also setting various other properties of the action. My question is how can this be done in C#? Thank-you for your kind help Luke :)
Sounds like you would be interested in this... Article Clickety[^]
-
Well, I'll take a stab at this. 1. I believe in C# you can assign the same event handler to multiple events. Just add the event function to the event handler, which, with regards to your question, can easily be done as part of the member of the control. 2. Multiple events can be assigned to the same handler. This is a nice feature, though I've never used it yet myself. 3. As far as iterating through a list of event handlers and enabling/disabling them, I don't believe this can be done (I don't think C# has a master event collection, but I could be wrong). This is why I personally vector everything through an event manager class, which not only lets me trace all events, but as you said, I can enable/disable events. I can also specify whether the event is run in-line or as a separate thread, and I've recently added the ability to do run time binding of events to functions based on the function assembly, class, and name, using C#'s reflection class. You said ...and also setting various other properties of the action. I'm curious--what other kinds of properties? Marc
Delphi actions have a few properties that can be set such as Caption, Category, Checked, Enabled, Hint, ImageIndex (for fetching the Actions icon), ShortCut Keys and a Visible property. These enable some really nice code management and thru the ActionList the actions can be managed and manipulated. I have even written code to enable action events to fire over COM. A fantastic way of building application extensibility. Cheers everyone for your help glad I came to this forum, hopefully soon enough I will be able to provide some advice too.
-
Well, I'll take a stab at this. 1. I believe in C# you can assign the same event handler to multiple events. Just add the event function to the event handler, which, with regards to your question, can easily be done as part of the member of the control. 2. Multiple events can be assigned to the same handler. This is a nice feature, though I've never used it yet myself. 3. As far as iterating through a list of event handlers and enabling/disabling them, I don't believe this can be done (I don't think C# has a master event collection, but I could be wrong). This is why I personally vector everything through an event manager class, which not only lets me trace all events, but as you said, I can enable/disable events. I can also specify whether the event is run in-line or as a separate thread, and I've recently added the ability to do run time binding of events to functions based on the function assembly, class, and name, using C#'s reflection class. You said ...and also setting various other properties of the action. I'm curious--what other kinds of properties? Marc
Marc Clifton wrote: . As far as iterating through a list of event handlers and enabling/disabling them, I don't believe this can be done (I don't think C# has a master event collection, but I could be wrong). This is why I personally vector everything through an event manager class, which not only lets me trace all events, but as you said, I can enable/disable events. I can also specify whether the event is run in-line or as a separate thread, and I've recently added the ability to do run time binding of events to functions based on the function assembly, class, and name, using C#'s reflection class. Ooooh. Can we see this in action...I believe that there's an article submission wizard somewhere around here...:-D Norm Almond: I seen some GUI's in my life but WTF is this mess ;-) Leppie: I made an app for my sister and she wouldnt use it till it was colorful enough:) Norm:good point leppie, from that statement I can only deduce that this GUI must be aimed at children:laugh: Leppie:My sister is 25:eek: -Norm on the MailMagic GUI
-
I come from a Delphi background, (just learning the C# and .Net). In Delphi, event handlers can be centralised using an action list. In this way I can assign the same event handler to as many cotrols as I like. In addition I can manage the event handlers by iterating thru the list and enabling as I wish and also setting various other properties of the action. My question is how can this be done in C#? Thank-you for your kind help Luke :)
nope, use the command pattern... see msdn http://msdn.microsoft.com/msdnmag/issues/02/10/CommandManagement/default.aspx[^]
"When the only tool you have is a hammer, a sore thumb you will have."
-
Marc Clifton wrote: 3. As far as iterating through a list of event handlers and enabling/disabling them, I don't believe this can be done (I don't think C# has a master event collection, but I could be wrong). This is why I personally vector everything through an event manager class, which not only lets me trace all events, but as you said, I can enable/disable events. I can also specify whether the event is run in-line or as a separate thread, and I've recently added the ability to do run time binding of events to functions based on the function assembly, class, and name, using C#'s reflection class. Article please!!!!:-D
In progress! :-D
-
Marc Clifton wrote: . As far as iterating through a list of event handlers and enabling/disabling them, I don't believe this can be done (I don't think C# has a master event collection, but I could be wrong). This is why I personally vector everything through an event manager class, which not only lets me trace all events, but as you said, I can enable/disable events. I can also specify whether the event is run in-line or as a separate thread, and I've recently added the ability to do run time binding of events to functions based on the function assembly, class, and name, using C#'s reflection class. Ooooh. Can we see this in action...I believe that there's an article submission wizard somewhere around here...:-D Norm Almond: I seen some GUI's in my life but WTF is this mess ;-) Leppie: I made an app for my sister and she wouldnt use it till it was colorful enough:) Norm:good point leppie, from that statement I can only deduce that this GUI must be aimed at children:laugh: Leppie:My sister is 25:eek: -Norm on the MailMagic GUI
Yup. Working on it. But I just read the link posted by Philip below, so I may have to rethink what I've done so far. :-D Marc
-
In progress! :-D