1

我的 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();
            }
}
4

1 回答 1

3

我将尝试使用本机命令来增加进度条而不计算增量
(当项目> 100 时会发生什么?)

progressBar1.Maximum = checkedListBox1.Items.Count;
progressBar1.Step = 1;
...
progressBar1.PerformStep();
于 2012-05-09T20:43:39.530 回答