I have written a method trial for button btnTrial1:
public void trial(object sender, EventArgs e, Button btn, TextBox txt, Label lbl)
{
}
In my application, i am generating more buttons and textboxes and labels dynamically through code and naming them sequentially like btnTrial2, txtTrial2, lblTrial2 then btnTrial3, txtTrial3, lblTrial3 and so on. Now i want to set trial as EventHandler for btnTrial2 then for btnTrial3 and so on.
So now when i call the method trial from btnTrial1, my parameters should be:
Public void (sender, e, btnTrail1, txtTrial1, lblTrial1)
But when i call the method trial from btnTrial2, my parameters should be:
Public void (sender, e, btnTrail2, txtTrial2, lblTrial2)
and so on…
You mention “generating them dynamically” – that is fine, but if you are in a loop you will also need to watch out for the infamous “captured variable / loop” problem – notably, the variables “captured” must be inside the loop; for example:
(if, for example,
btnTrialwas declared outside the loop, bad things would happen)