notification techniques in nested user controls

M

Marek

Hi,

I have a Form with many UserControls on it. Some of the UserControls contain
other Controls.
What is the best way of notifying each of the nested controls about an event
that has occured on one of them?
Are there any mechanisms for broadcasting messages down the owning chain?

Mark
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Marek
No, there is no any mechanism that will automate that for you. The only
mechanism that WindowsForms supports are events. But each control that wants
to be notified needs to hook on that event.

The easiest way I believe (ofcourse it is not a painkiller and might be not
suitable for some projects) is to declare helper serivice class that
exposes a static public events and respective public static raise methods.
This way the events are accessible to any object that wants to hook on them
and any object can raise some of those events using the RaiseXXX methods if
wants to notify the others. Over simmilar pattern VS, for example, is built.
Ofcourse they have more powerful and flexible service system (with service
containers and stuff) rather than static events.
 
M

Marek

Thank you for your help.

Stoitcho Goutsev (100) said:
Hi Marek
No, there is no any mechanism that will automate that for you. The only
mechanism that WindowsForms supports are events. But each control that
wants to be notified needs to hook on that event.

The easiest way I believe (ofcourse it is not a painkiller and might be
not suitable for some projects) is to declare helper serivice class that
exposes a static public events and respective public static raise methods.
This way the events are accessible to any object that wants to hook on
them and any object can raise some of those events using the RaiseXXX
methods if wants to notify the others. Over simmilar pattern VS, for
example, is built. Ofcourse they have more powerful and flexible service
system (with service containers and stuff) rather than static events.


--
HTH
Stoitcho Goutsev (100) [C# MVP]

Marek said:
Hi,

I have a Form with many UserControls on it. Some of the UserControls
contain other Controls.
What is the best way of notifying each of the nested controls about an
event that has occured on one of them?
Are there any mechanisms for broadcasting messages down the owning chain?

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top