Yes.
All event handlers have two parameters:
object
sender and
EventArgs
e
The
sender
parameter is the control which raised the event. so in your "combined" handler, just cast the parameter to a ComboBox:
private void MyComboEvent_Handler(object sender, EventArgs e)
{
ComboBox db = sender as ComboBox;
if (cb != null)
{
...
}
}
You can then pass the Combobox instance through to your OverTime method and you get the current instance.
If however you are trying to make the same code work for seven different comboboxes, thats simple as well:
public double Overtime()
{
double Salary = double.Parse(txtSalary.Text);
double total = OverTime(cbOTType1, Salary);
total += OverTime(cbOTType2, Salary);
total += OverTime(cbOTType3, Salary);
total += OverTime(cbOTType4, Salary);
total += OverTime(cbOTType5, Salary);
total += OverTime(cbOTType6, Salary);
total += OverTime(cbOTType7, Salary);
return total;
}
private double OverTime(ComboBox cb, double salary)
{
double x = salary / 26 / 8;
double total;
if (cb.SelectedItem.ToString() == "Regular")
{
total = ((x * 1.25);
}
else if (cb.SelectedItem.ToString() == "Rest Day OT")
{
total = ((x * 1.69);
}
else
{ total = 0.0; }
return total;
}