private void Form1_Load(object sender, EventArgs e)
{
progressBar1.Minimum = 0;
progressBar1.Maximum = 10;
progressBar1.Step = 1;
}
private void button1_Click(object sender, EventArgs e)
{
for (int idx = progressBar1.Minimum; idx < progressBar1.Maximum; idx++)
{
progressBar1.PerformStep();
// progressBar1.Value ++; - либо так по-деревенски
MessageBox.Show((idx + 1).ToString());
}
MessageBox.Show("Done!");
}
ProgressBar и процесс выполнения всех методов
Код:
private void button1_Click(object sender, EventArgs e)
{
int T = Convert.ToInt32(textBox1.Text);
int U = Convert.ToInt32(textBox2.Text);
double shag = Convert.ToDouble(textBox3.Text);
int frc = Convert.ToInt32(textBox4.Text);
int frc1 = Convert.ToInt32(textBox5.Text);
int frequency, counter;
List<Complex> values = new List<Complex>();
progressBar1.Value = 0;
var timer = new System.Windows.Forms.Timer();
timer.Interval = 100;
timer.Tick += (s, a) =>
{
progressBar1.Value += 5;
if (progressBar1.Value == progressBar1.Maximum)
{
timer.Stop();
button1.Enabled = true;
}
};
timer.Start();
for (frequency = frc, counter = 1; frequency <= frc1; frequency++, counter++)
{
values.Add(reverstrans(U, frequency, T, frc, frc1,shag));
}
values.ForEach(x1 => dataGridView1.Rows.Add(x1.Real, x1.Imaginary));
drawreverse(U,T, shag, frc, frc1);
drawgraph(U, T, frc, frc1, frequency, shag);
}
{
int T = Convert.ToInt32(textBox1.Text);
int U = Convert.ToInt32(textBox2.Text);
double shag = Convert.ToDouble(textBox3.Text);
int frc = Convert.ToInt32(textBox4.Text);
int frc1 = Convert.ToInt32(textBox5.Text);
int frequency, counter;
List<Complex> values = new List<Complex>();
progressBar1.Value = 0;
var timer = new System.Windows.Forms.Timer();
timer.Interval = 100;
timer.Tick += (s, a) =>
{
progressBar1.Value += 5;
if (progressBar1.Value == progressBar1.Maximum)
{
timer.Stop();
button1.Enabled = true;
}
};
timer.Start();
for (frequency = frc, counter = 1; frequency <= frc1; frequency++, counter++)
{
values.Add(reverstrans(U, frequency, T, frc, frc1,shag));
}
values.ForEach(x1 => dataGridView1.Rows.Add(x1.Real, x1.Imaginary));
drawreverse(U,T, shag, frc, frc1);
drawgraph(U, T, frc, frc1, frequency, shag);
}
Если я сделаю вот так
Код:
private void button1_Click(object sender, EventArgs e)
{
int T = Convert.ToInt32(textBox1.Text);
int U = Convert.ToInt32(textBox2.Text);
double shag = Convert.ToDouble(textBox3.Text);
int frc = Convert.ToInt32(textBox4.Text);
int frc1 = Convert.ToInt32(textBox5.Text);
int frequency, counter;
List<Complex> values = new List<Complex>();
progressBar1.Maximum = 500;
for (frequency = frc, counter = 1; frequency <= frc1; frequency++, counter++)
{
values.Add(reverstrans(U, frequency, T, frc, frc1,shag));
progressBar1.Value += frequency ;
}
values.ForEach(x1 => dataGridView1.Rows.Add(x1.Real, x1.Imaginary));
drawgraph(U, T, frc, frc1, frequency, shag);
drawreverse(U, T, shag, frc, frc1);
}
{
int T = Convert.ToInt32(textBox1.Text);
int U = Convert.ToInt32(textBox2.Text);
double shag = Convert.ToDouble(textBox3.Text);
int frc = Convert.ToInt32(textBox4.Text);
int frc1 = Convert.ToInt32(textBox5.Text);
int frequency, counter;
List<Complex> values = new List<Complex>();
progressBar1.Maximum = 500;
for (frequency = frc, counter = 1; frequency <= frc1; frequency++, counter++)
{
values.Add(reverstrans(U, frequency, T, frc, frc1,shag));
progressBar1.Value += frequency ;
}
values.ForEach(x1 => dataGridView1.Rows.Add(x1.Real, x1.Imaginary));
drawgraph(U, T, frc, frc1, frequency, shag);
drawreverse(U, T, shag, frc, frc1);
}
Как можно выйти из этой ситуации?
Код:
for (frequency = frc, counter = 1; frequency <= frc1; frequency++, counter++) // можно только догадываться что у вас там подается в текстбоксы?
{
values.Add(reverstrans(U, frequency, T, frc, frc1,shag));
progressBar1.Value += frequency ;
}
{
values.Add(reverstrans(U, frequency, T, frc, frc1,shag));
progressBar1.Value += frequency ;
}
minimum - начало отсчета
maximum - конец отсчета (количество ротаций или циклов)
Код: