Working on a simple Windows form calculator to learn delegates. I have it set up when you click a button it adds that operation to my list. There is an input textbox that checks to see if the input is a double in another class. I want it to update the ouput each time I click a button or change the "input". I am just stuck and the calculation portion. Can anyone give me some guideance? I didn't put in all the code for all the different buttons to keep it short, but here is the general idea:
Code:
public partial class Form1 : Form
{
delegate double Operation(double Value); //declare delegate that takes a "double"
public Form1()
{
InitializeComponent();
double CurrentValue;
try
{
foreach (Operation O in this.Operators)
{
CurrentValue = O(doubleValueEdit1.Value);
if (CurrentValue < 0)
break;
tbOutput.Text = (CurrentValue.ToString("0.00"));
}
}
catch
{
}
}
List<Operation> Operators = new List<Operation>();
private double Add1(double i)
{
return (i + 1);
}
private void bAdd1_Click(object sender, EventArgs e)
{
this.Operators.Add(new Operation(this.Add1));
lActionTaken.Text = lActionTaken.Text + bAdd1.Text + ", ";
}
private void tbOutput_TextChanged(object sender, EventArgs e)
{
}
private void doubleValueEdit1_TextChanged(object sender, EventArgs e)
{
}
}
}