日期:2014-05-18 浏览次数:20875 次
private void button1_Click(object sender, EventArgs e) { c1 = bylProbar.Position; btnStart.Enabled = false; btnClose.Enabled = false; //控制进度条速度 timer1.Interval = 600; timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { if (c1 == bylProbar.PositionMax) { p1 = 0; timer1.Stop(); bylProbar.Text = "完成!"; btnClose.Enabled = true; } else { if (c1 == bylProbar.PositionMin) { p1 = 1; } else if (c1 == 2) { Thread t1 = new Thread(new ThreadStart(ThreadDBImportForums)); t1.Start(); } else if (c1 == 5) { Thread t2 = new Thread(new ThreadStart(ThreadDBTranfer)); t2.Start(); } else if (c1 == 9) { Thread cha = new Thread(new ThreadStart(ThreadDBImportBlog)); cha.Start(); } } c1 += p1; Application.DoEvents(); bylProbar.Text = c1.ToString() + " %"; bylProbar.Position = c1; if (rows > 0) timer1.Interval = 20; } private void Form1_Load(object sender, EventArgs e) { bylProbar.Text = ""; bylProbar.Position = 0; }
------解决方案--------------------
int b = 总数
int b1 = b;
progressBar1.Maximum = b1;
while (b > 0)
{
b = b - 1;
获取文件一条
int b2 = b + 1;
progressBar1.Value = b1 / b2;
}