C#进度条的问题
privatevoidForm3_Load(objectsender,EventArgse){this.progressBar1.Enabled=true;this.pr...
private void Form3_Load(object sender, EventArgs e)
{
this.progressBar1.Enabled = true;
this.progressBar1.Value = 0;
this.progressBar1.Maximum = 100;
this.progressBar1.Minimum = 0;
this.progressBar1.Step = 50;
this.timer1.Enabled = true;
this.timer1.Start();
}
private void timer1_Tick_1(object sender, EventArgs e)
{
if (this.progressBar1.Value< 100)
this.progressBar1.Value = this.progressBar1.Value + 20;
if (this.progressBar1.Value == 100)
{
timer1.Enabled = false;
Form4 form4 = new Form4();
form4.Show();
this.Hide();
}
}
}
为什么进度条还没有读完,就show form4 了
应当怎么改 展开
{
this.progressBar1.Enabled = true;
this.progressBar1.Value = 0;
this.progressBar1.Maximum = 100;
this.progressBar1.Minimum = 0;
this.progressBar1.Step = 50;
this.timer1.Enabled = true;
this.timer1.Start();
}
private void timer1_Tick_1(object sender, EventArgs e)
{
if (this.progressBar1.Value< 100)
this.progressBar1.Value = this.progressBar1.Value + 20;
if (this.progressBar1.Value == 100)
{
timer1.Enabled = false;
Form4 form4 = new Form4();
form4.Show();
this.Hide();
}
}
}
为什么进度条还没有读完,就show form4 了
应当怎么改 展开
2个回答
展开全部
你好,之所以我们看到“进度条还没有读完”,是因为在form3界面将progressbar绘制成进度为100的操作,几乎同this.hide()同时进行,这样用户的感觉就是进度条还没有“读完”。解决方法是:我们增加一个标记成员。
代码如下:
private bool m_loadCompleted = false; // 标记字段
private void Form3_Load(object sender, EventArgs e)
{
this.progressBar1.Enabled = true;
this.progressBar1.Value = 0;
this.progressBar1.Maximum = 100;
this.progressBar1.Minimum = 0;
this.progressBar1.Step = 50;
this.timer1.Enabled = true;
this.timer1.Start();
}
private void timer1_Tick_1(object sender, EventArgs e)
{
if (m_loadCompleted)
{
timer1.Enabled = false;
Form4 form4 = new Form4();
form4.Show();
this.Hide();
}
if (this.progressBar1.Value < 100)
this.progressBar1.Value = this.progressBar1.Value + 20;
if (this.progressBar1.Value == 100)
{
m_loadCompleted = true;
this.timer1.Interval = 300;
return;
}
}
这样用户就能够很清楚的看到进度条满了后,才进入form4窗体。
代码如下:
private bool m_loadCompleted = false; // 标记字段
private void Form3_Load(object sender, EventArgs e)
{
this.progressBar1.Enabled = true;
this.progressBar1.Value = 0;
this.progressBar1.Maximum = 100;
this.progressBar1.Minimum = 0;
this.progressBar1.Step = 50;
this.timer1.Enabled = true;
this.timer1.Start();
}
private void timer1_Tick_1(object sender, EventArgs e)
{
if (m_loadCompleted)
{
timer1.Enabled = false;
Form4 form4 = new Form4();
form4.Show();
this.Hide();
}
if (this.progressBar1.Value < 100)
this.progressBar1.Value = this.progressBar1.Value + 20;
if (this.progressBar1.Value == 100)
{
m_loadCompleted = true;
this.timer1.Interval = 300;
return;
}
}
这样用户就能够很清楚的看到进度条满了后,才进入form4窗体。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询