窗体上有个Button控件,
点击控件,就去执行一些操作,操作完成后,进度条就满了.然后隐藏进度条控件

解决方案 »

  1.   


    Progressbar1.value=0;
    Progressbar1.maximize=100;
    for(int =0;i<100;i++)
    {
         Progressbar1.value=Progressbar1.value+1;
         Progressbar1.update();
    }
    Progressbar1.visible=false;
      

  2.   


            private void button1_Click(object sender, EventArgs e)
            {
                for (int i = 0; i < 100; i++)
                {
                    this.progressBar1.Value = i;
                    
                }            Thread.Sleep(200); //以免太快没效果            this.progressBar1.Visible = false;
            }
      

  3.   


    ^_^ Thread.Sleep(200);应该放到for里面吧 
      

  4.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication3
    {
        public partial class frmPrograss : Form
        {
            public frmPrograss()
            {
                InitializeComponent();
            }        private int GetStep()
            {
                Random ran = new Random(DateTime.Now.Millisecond);
                return ran.Next(10, 30);
            }        private string[] arr ={ 
            "系统加载数据中,请稍候.",
                "系统加载数据中,请稍候...",
                "系统加载数据中,请稍候.....",
                "系统加载数据中,请稍候.......",
                "系统加载数据中,请稍候..........",
                "系统加载数据中,请稍候..............",
                "系统加载数据中,请稍候.................",
                "系统加载数据中,请稍候....................",
                "系统加载数据中,请稍候........................",
            };        private int i = 2;        private void timer1_Tick(object sender, EventArgs e)
            {
                if (this.label1.ForeColor == Color.Black)
                {
                    this.label1.ForeColor = Color.Red;
                    
                }
                else
                {
                    this.label1.ForeColor = Color.Black;
                }            if (i <= arr.Length - 1)
                {
                    this.label1.Text = arr[i];
                    i++;
                }            int step = this.GetStep();
                if (this.progressBar1.Value + step < this.progressBar1.Maximum)
                {
                    this.progressBar1.Value = this.progressBar1.Value + step;
                    return;
                }
                else
                {
                    this.timer1.Enabled = false;
                    this.progressBar1.Value = this.progressBar1.Maximum;
                    Form1 frm = new Form1();
                    this.Hide();
                    frm.Show();            }        }        private void frmPrograss_Load(object sender, EventArgs e)
            {
                this.timer1.Enabled = true;
            }
        }
    }
      

  5.   

    恩 4楼说的对 要把
    Thread.Sleep(200); 
    放在 for循环里,效果就出来了。
      

  6.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;//加此命名空间namespace WindowsApplication2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
            
                   for (int i = 0; i < 100; i++) 
                { 
                    this.progressBar1.Value = i; 
                    
                    Thread.Sleep(20); //设为20就可以了
                } 
                this.progressBar1.Visible = false;         }        
        }
    }