Here's an explanation of what I'm trying to achieve:
I have a textbox that I'm using as a 'debug', or 'information' window on my form. What I would like to do is have any classes that I create throw an event when it has information to post to the debug window, and then have the text window subscribe to said event, and post each time something new comes in. I'm trying to make it so that my classes don't need knowledge of the textbox but still have the capability to pass all of the information to the text box.
Is it possible to have a 'shared' event among classes (perhaps using an interface) so that I only need to subscribe to that one event and it will pull from all classes that throw the event?
For a visual, it would basically look like this:
Public delegate void DebugInfo(string content)
Class foo1
{
event DebugInfo DebugContentPending
public void bar()
{
DebugContentPending("send this info to the debug window")
}
}
Class foo2
{
event DebugInfo DebugContentPending
public void bar()
{
DebugContentPending("send this info to the debug window")
}
}
Class SomeClass
{
public void SomeMethod()
{
DebugContentPending += new DebugInfo(HandleContent); //gets events from foo1 and foo2
}
public void HandleContent(string content)
{
//handle messages
}
}
is this possible or am I off my rocker?