> I have a user control (called MyControl that inherits from
> CompositeControl). This control will raise an event when the user
[quoted text clipped - 13 lines]
>
> Phil
In the user control
* Define a Delegate
* Define an event based on the delegate
* Fire the event
In the "listener" controls
* subscribe to the event
* write an event handler
* "wire" the event handler to the delegate
/*************** Event Publisher ****************/
public PublisherClass { // the class that changed it's color
pubic delegate void myDelegate(string newColor);
public event myDelegate myEvent;
// "wire" this method to the OnChange property of your Select listbox.
private void OnColorChange(string theNewColor) {
this.myEvent();
}
}
/*********** meanwhile, in the listener contols' code ***********/
public ListenerClass {
PublisherClass myPublisher = new PublisherClass();
override protected void OnInit (EventArgs e) {
myPublisher.myEvent += myPublisher.myDelegate(ChangeMyColor);
}
public void ChangeMyColor (string newColor) {
// change the color to newColor
}
}
/************ Caveat **************/
If you want every control to listen to every other control's
ChangeColor event then I'm not sure
how to neatly implement that. I guess every control will be both a
publisher and subscriber - sounds cool, if it works - Either every
control defines it's own event and all controls subscribe to all other
control's events.. OR .. here's something wacky: think it *could* go
like this (WARNING: wild-a.s guess follows):
* Define the delegate and event at the namespace level (i.e. at the
container page level?)
* Each control will have an OnChange handler for what I assume is a
drop-down select list of colors
* In that OnChange handler of every control, call the event
* in OnInit() of every control set "this.myEvent +=
this.myDelegate(ChangeMyColor)" (not too sure that "this" will cut it)
* so the drop-down list event handler fires the event and a separate
method (wired to the delegate) does the actual work
***** would this cause an infinite loop?
Phil - 19 Oct 2006 00:55 GMT
Thanks for the response. I managed a workaround, but your suggestions is
much neater. Will try to implement it this way!
>> I have a user control (called MyControl that inherits from
>> CompositeControl). This control will raise an event when the user
[quoted text clipped - 67 lines]
> method (wired to the delegate) does the actual work
> ***** would this cause an infinite loop?