using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { progressBar1.Maximum=int.Parse(textBox1 .Text ); for (int i = 0; i < int.Parse(textBox1.Text)+1; i++) { progressBar1.Value = i; label1.Text = ((100 * i) / (int.Parse(textBox1.Text))).ToString() + "%"; label1.Refresh(); } } } }
pb.Value = (int)rowRead;
percent = ((float)(100 * rowRead)) / totalCount;
ll.Text = percent.ToString("0.00").Trim() + "%";
追踪一下上面三行代码;
建议去掉long rowRead = 0; float percent = 0;直接用i .也不要进行浮点转换和计算了,浪费时间,还容易出错
Pbar.PerformStep();
Pbar.Value =(int)rowRead;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
progressBar1.Maximum=int.Parse(textBox1 .Text );
for (int i = 0; i < int.Parse(textBox1.Text)+1; i++)
{
progressBar1.Value = i;
label1.Text = ((100 * i) / (int.Parse(textBox1.Text))).ToString() + "%";
label1.Refresh();
} }
}
}