I got a main button function, where i parse the textbox text values, then I pass those values to an another method.
After performing the first calculation, then i want to pass those parameters to another button function.
I want to assign int valueOF1, int valueOF2to this method public void testfunction(object sender, EventArgs ea) from the main button.
How can i do this?? Thank you for your help.
This is the code:
private void b_calculate_Click(object sender, EventArgs e)
{
int valueOF1;
int.TryParse(t_Offset1.Text, NumberStyles.Any,
CultureInfo.InvariantCulture.NumberFormat, out valueOF1);
int valueOF2;
int.TryParse(t_Offset2.Text, NumberStyles.Any,
CultureInfo.InvariantCulture.NumberFormat, out valueOF2);
int pRows = PrimaryRadGridView.Rows.Count;
int sRows = SecondaryRadGridView.Rows.Count;
if (pRows == 1 && sRows == 1)
{
calculatePS(valueOF1, valueOF2);
}
}
private void calculatePS(int valueOF1, int valueOF2)
{
MessageBox.Show("You are using : P-S");
// Do some calculation & go to the next function ///
Button2.Enabled = true;
Button2.Click += testfunction; // Here i want to pass the valueOF1 & valueOF2
}
public void testfunction(object sender, EventArgs ea)
{
MessageBox.Show("you...!");
Button2.Enabled = false;
}
You can declare
valueOF1andvalueOF2as class fields, so you can access them from different methods.Here’s how the code could look like:
Additional Note:
int.TryParsereturns aboolvalue that tells you whether the parse succeeded. In case the return isfalse, you may want to handle the parse error somehow instead of continuing with the normal flow.