using System;
using System.Windows.Forms;
namespace SomeTestingNamespace
{
//declare delegate with one additional argument
public delegate EventDelegate(string arg1);
public static class Program
{
//the main entry point of the program
[STAThread]
static void Main()
{
Application.Run(MainClass());
}
}
//this must be a form derrived class
public class MainClass()
{
//declare the event based on delegate (above)
public event EventDelegate EventInvoker;
//declare and instantiate the "other" class
public SecondaryClass sClass = new SecondaryClass();
//the main class of the application
public int MainClass()
{
//instantiate event
EventInvoker += new EventDelegate(sClass.ExecuteAction);
//just pretend we fire up the event, method with event to be exact
SomeMethod("Some argument typeof string");
//finish the execution
return 0;
}
//some method which invokes the delegate event
private void SomeMethod(string dataToPass)
{
EventInvoker(dataToPass);
}
}
//the other class, might be, as well imported from plugin, loaded from assembly... w/e
public class SecondaryClass()
{
public SecondaryClass()
{
//initialize smth ! ... or not :P
}
public void ExecuteAction(string dataToPass)
{
Message.Show("Event Fired with arg: " + dataToPass + "!");
}
}
}