It possible you mean something like this:
private delegate void BoilerLogHandler(string status);
BoilerLogHandler theDelegate = BoilerLogHandlerB;
private void myCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (myCheckBox.Checked)
{
theDelegate = BoilerLogHandlerA;
}
else
{
theDelegate = BoilerLogHandlerB;
}
}
private void myButton_Click(object sender, EventArgs e)
{
theDelegate("Hello from a button click!");
}
private static void BoilerLogHandlerA(string status)
{
Console.WriteLine("A: {0}", status);
}
private static void BoilerLogHandlerB(string status)
{
Console.WriteLine("B: {0}", status);
}
When you change the status of the checkbox, it changes the delegate. And when you click the button, the delegate is used to call whichever method is currently set.
For an event it's slightly different:
public event EventHandler TestEvent;
protected virtual void OnTestEvent(EventArgs e)
{
EventHandler eh = TestEvent;
if (eh != null)
{
eh(this, e);
}
}
private void myCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (myCheckBox.Checked)
{
TestEvent +=frmMain_TestEventA;
}
else
{
TestEvent += frmMain_TestEventB;
}
}
void frmMain_TestEventA(object sender, EventArgs e)
{
Console.WriteLine("EventA");
}
void frmMain_TestEventB(object sender, EventArgs e)
{
Console.WriteLine("EventB");
}
private void myButton_Click(object sender, EventArgs e)
{
OnTestEvent(new EventArgs());
}
Now each time you change the CheckBox, another handler is added to the event.
Since an event is internally implemented via a delegate, you can also use the "+=" syntax with delegates to "chain" methods into it, but that's a little more rare to do directly.