Good day, community. Help a novice C # WindowsForms programmer. There is a task: to write a program for counting

X = x1 + x2 + ... + xn, xn = zn ^ 3-bn + an ^ 2 / tan (Bettan).

On Form1 I enter n , and I want for each xn open a form for entering z,a,b,betta . Decided to do in a loop:

 for (i = 0; i < n; i++) { Input.Show(); X[i] = Z[i] * Z[i] * Z[i] - B[i] + (A[i] * A[i]) / Math.Tan(Betta[i]); } 

But the cycle opens at once n forms, it is not convenient. I could not implement a pause in the cycle either. Question: "How can I make the forms open one by one? Or can you tell me how to make convenient data entry in another way?" Thanks in advance to everyone who responds.

  • Input is what you have? - BlackWitcher

1 answer 1

To solve your problem and enter the values ​​of z, a, b, betta in a loop in turn, you can use (almost) any form inherited from standard with fields (input field), calling it through ShowDialog() and not via Show() . For example, if your Input form is inherited from a standard form, then call it like this:

 Input.ShowDialog(); 

You can extend the functionality and process some additional conditions, if you also handle the result of such a call, for example, like this:

 if (Input.ShowDialog() == DialogResult.OK) {.......//Что-то делаем} else if (if (Input.ShowDialog() == DialogResult.Cancel)) { //Пользователь нажал отмену или просто закрыл форму } 

If you call ShowDialog() , then your form is called as a modal form, i.e. in your case, the program will not continue its work (cycle) until the form is hanging on the screen and the user has not closed it in one way or another.

Instead of this form, you can use the InputBox :

 string input = Microsoft.VisualBasic.Interaction.InputBox("Prompt", "Title", "DefaultValue", -1, -1); 

Or realize your form, for example, it is proposed to do it here .

PS I would not use such an approach, except for debugging purposes, and even if n is small enough, otherwise if it is, for example, 50 or 100, then the user will be tempted to enter values. But this is a completely different question.

  • Thanks a lot, they helped a lot) - Alexander Pozdniakov