using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace WpfApplication2
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }        private void showPro(int value)
        {
            this.progressBar1.Value = value;
            this.label1.Content = value + "%";
            
            System.Threading.Thread.Sleep(1000);//停止一秒后继续+        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {            int xueTiao = 0;
            while (xueTiao < 100)
            {                xueTiao++;
                showPro(xueTiao);
                
            }
            MessageBox.Show("满了");        }    }
}
进度条

解决方案 »

  1.   

    不建议这样弄,这样弄即使有递增过程也是假的,建议你的 xueTiao++;放到实际业务处理完成后
      

  2.   


    while (true)
                {
                    //System.Threading.Thread.Sleep(500); 此处可以加这句
                    progressBar1.Value += 1;
                    if (progressBar1.Value>=progressBar1.Maximum)
                    {
                        return;
                    }
                }
      

  3.   

    界面要刷新吧,在private void showPro(int value)         
    {             
    this.progressBar1.Value = value;             
    this.label1.Content = value + "%";    
    Application.DoEvents();//加这条,将消息给处理显示到界面上System.Threading.Thread.Sleep(1000);//停止一秒后继续+           } 
      

  4.   

    错误1“System.Windows.Application”并不包含“DoEvents”的定义报错啊!没有这个方法貌似
      

  5.   

    你是错误1“System.Windows.Application”并不包含“DoEvents”的定义报错啊!没有这个方法貌似

    可能少了引用吧,百度下Application.DoEvents
    顺便说下,这个方法界面还是会卡,毕竟是单线程的,用委托的方法界面会流畅些。
      

  6.   


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using System.Threading;namespace WpfApplication2
    {
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }        private void showPro(int value)
            {            this.Invoke((EventHandler)delegate
                {
                    this.progressBar1.Value = value;
                    this.label1.Content = value + "%";
                });            System.Threading.Thread.Sleep(1000);//停止一秒后继续+        }
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                Thread th = new Thread(new ThreadStart(ProgressBarAdd));
                th.Start();        }        private void ProgressBarAdd()
            {
                int xueTiao = 0;
                while (xueTiao < 100)
                {                xueTiao++;
                    showPro(xueTiao);            }
                MessageBox.Show("满了");
            }    }
    }