簡體   English   中英

C#動態ProgressBar

[英]C# dynamic ProgressBar

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

我將嘗試使用native命令增加進度條而不計算增量
(當項目> 100時會發生什么?)

progressBar1.Maximum = checkedListBox1.Items.Count;
progressBar1.Step = 1;
...
progressBar1.PerformStep();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM