我的winform有一个进度条,应该根据程序正在处理的文件数量增加。它在一个盒子上运行正常(win xp)但在另一个盒子上运行正常(winserver 2008)。在过程结束时,栏未完全填满。两者都有相同的.net框架3.5
private void data_process()
{
int progress_num = (100/checkedListBox1.Items.Count);
.......
progressBar1.Value = progressBar1.Value + progress_num;}
你知道为什么吗?你有更好的解决方案吗?
------这是新代码
private void button1_Click(object sender, EventArgs e)
{
progressBar1.Value = 0;
richTextBox1.Clear();
richTextBox1.Focus();
if (checkedListBox1.CheckedItems.Count < 1)
{
MessageBox.Show("No file is selected", "Warning");
}
else
{
if ((region != null) && (venue != null) && (lhversion != null) && (release_version != null) && (desc != null))
{
progressBar1.Maximum = checkedListBox1.Items.Count + 3;
progressBar1.Step = 1;
//progressBar1.Value = progressBar1.Value + 10;
progressBar1.PerformStep();
login();
//progressBar1.Value = progressBar1.Value + 10;
progressBar1.PerformStep();
data_process();
//progressBar1.Value = progressBar1.Value + 10;
progressBar1.PerformStep();
if (user_in == true)
{
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.AppendText("Done");
}
}
private void data_process()
{
string line;
//int progress_num = (70/checkedListBox1.Items.Count);
foreach (object itemChecked in checkedListBox1.CheckedItems) // for each selected file
{
...
progressBar1.PerformStep();
}
}
答案 0 :(得分:3)
我将尝试使用native命令增加进度条而不计算增量
(当项目> 100时会发生什么?)
progressBar1.Maximum = checkedListBox1.Items.Count;
progressBar1.Step = 1;
...
progressBar1.PerformStep();