foreach(Control c in Controls)
ComboBox cb = c as ComboBox;
if (cb != null)
cb.SelectedIndex = 0;
this loops through ALL the controls on the current form, that's buttons, checkboxs, textboxes etc. There are a lot of controls on a form. So, as you're looping through, if you try and treat an object that is NOT a checkbox like a checkbox, it will error. Soooooo.... you test to see if the conversion to ComboBox worked. You can't easily select JUST ComboBoxes from a form, you have to go through the controls.
First, your delegate doesn't need to conform to the object/eventargs model, it can have any signature.
Second, it looks like you're trying to pass the listbox to the delegate. Why ? That misses the whole point. The point is, your delegate method should fire in the scope of the listbox, and the code to work with the listbox should run locally. If you're going to pass the listbox, the code could be anywhere, so why use delegates ?
No longer a Microsoft MVP, but still happy to answer your questions.
Thanks, but even so when I start the program it still doesn't pass on the message, start button activtes the begin button whic should send a message a that is not happening whether I use a delegate or not, yet the begin button will load a message.
Everything compiles and runs but nothing happens when the delegate runs the buttonBegin, I expected to see "Start Reactor" as I would when I click on the button itself. Here is an updated copy, which is what I originally had before playing with it to try different ideas.
public delegate void DelegateReactorMessage(String message);
public delegate void DelegatebuttonStart_Click(object sender, EventArgs e);
public delegate void DelegatebuttonBegin_Click(object sender, EventArgs e);
static class Program
/// The main entry point for the application.
public static void Main()
public partial class FormStartReactor : Form
static FormReactor FR = new FormReactor();
Action<String> delegateReactorMessage = FR.ReactorMessage;
DelegatebuttonBegin_Click delegatebuttonBegin = new DelegatebuttonBegin_Click(FR.buttonBegin_Click);
public void buttonStart_Click(object sender, EventArgs e)
FormReactor FR = new FormReactor();
Reactor myReactor = new Reactor();
ReactorMonitor myReactorMonitor = new ReactorMonitor(myReactor);
// Set myReactor to 100 degrees Celcius
delegateReactorMessage("Setting reactor temperature to 100 degrees Celcius");
myReactor.Temperature = 100;
// Set myReactor to 500 degrees Celcius
delegateReactorMessage("Setting reactor temperature to 1500 degrees Celcius");
myReactor.Temperature = 1500;
// Set myReactor to 2000 degrees Celcius
delegateReactorMessage("Setting reactor temperature to 3000 degrees Celcius");
myReactor.Temperature = 3000;
public delegate void MeltdownHandler(Object reactor, MeltdownEventArgs myMEA);
public event MeltdownHandler OnMeltdown;
public Int32 Temperature
temperature = value;
if (temperature > 1000)
if (temperature < 2000)
strReactorMessage = "Reactor meltdown in progress";
strReactorMessage = "The reactor is critical, YOU ARE DEAD, DEAD, DEAD";