I have a Start and a Done button on a windows form, and I have vehicles stored in a list.
private void btnStart_Click(object sender, EventArgs e) { Start(); } private void Start() { for (int i = 0; i < vehicles.Count; i++) { txtLicensePlate.Text = vehicles[i].LicensePlate; } So by clicking on the start button makes the txtLicensePlate textbox show the car's license plate number one by one. But before moving on from a license plate number, I would like the for loop to wait for a button click.
private void btnDone_Click(object sender, EventArgs e) { Add(); } I tried to invoke the event handler like this:
private void Start() { for (int i = 0; i < vehicles.Count; i++) { txtLicensePlate.Text = vehicles[i].LicensePlate; btnDone_Click(sender, e); } But I got an error message saying, that "sender and e does not exist in the current context". And on the other hand it seems I want the loop to trigger the button click on it's own (which is not my intention), and this leads to my question:
How can make the for loop to wait for a button click by the user?
Edit: Seems like I caused a little confusion, so I'd like to clarify: The Start button would start the loop showing the first license plate number. Then the user can "tell" if the current vehicle will go for a run, and if it will how many kilometres it will run. When the user clicks the Done button, the amount of kilometres will added to the vehicle, and the next license plate number should be shown.
Addmethod and then you display the next plate number? Does theAddmethod involve anything in the UI (I am making the assumption that it is going to read from the text box)?Startbutton would start the loop showing the first license plate number. Then the user can "tell" if the current vehicle will go for a run, and if it will how many kilometres it will run (via textbox). When the user clicks theDonebutton, the amount of kilometres will added to the vehicle, and the next license plate number should be shown.