A button has been added to the form, after which a certain cycle is executed.
private void button1_Click(object sender, EventArgs e){ for (int i = 1; i <= numVal; i++) At the end of the loop iteration, you need to change the value of the ProgressBar located on the same form, do this:
progressBar1.Value = (i / numVal) * 100; Unfortunately, the ProgressBar value is not updated during the iterations of the loop, but becomes equal to 100 (the maximum value for it) after all iterations have been completed.
The same happens with TextBox located on the same form.
The execution time of all iterations of the loop is not so short that changes cannot be seen (each iteration is on average 7 seconds).
Tell me what needs to be changed in order for the ProgressBar and TextBox updates to occur during the execution of the cycle, and not after it has been completely worked out?
(i / numVal)because 100 appears only at the last iteration, and all the others are 0. Change to(double)i / numVal. - 伪位蔚蠂慰位蠀蟿Application.DoEvents();after setting the new value of the progress bar. - 伪位蔚蠂慰位蠀蟿