Lucean Morningside wrote:
Thank you for taking the time to reply and especially the sample code.
When you talk about design patterns, where can I learn more about these? Are
you talking about books that are dedicated to design patterns? I'm quite
new to C# but have coded extensively in C but of course C# is object
oriented and quite a bit different.
TIA for any info on design patterns.
Dunster
class MyEventObserver
{
public void clickEventHandler( object src, EventArgs args )
{
// your even handling code here
}
}
class MyForm
{
private MyEventObserver m_observer = new MyEventObserver();
private Button m_dynamicButton = null;
.
.
.
public void CreateAndBindButton()
{
m_dynamicButton = new Button( ... );
m_dynamicBytton.Click += new EvenHandler(
m_observer.clickEventHandler );
}
}
So, yes. It can be done. There's even a whole design parttern dedicated to
this behavior: the Observer pattern, and the closely related
Model-View-Controller (MVC) pattern.
-LM