读书人

哪位高手有现成的进度条ProgressBar的

发布时间: 2012-05-22 18:18:54 作者: rapoo

谁有现成的进度条ProgressBar的例子,或者是哪里有下载的...........
谁有进度条的例子哟!

就像windows系统复制稍微大点文件时出现的那个进度提示窗体一样.....最好是能弹出一个窗体来的

有的就发出来吧 或者发到我的邮箱:bwang3630478@126.com



[解决办法]
你说的是哪个啊
[解决办法]
Ajax的,直接上http://ajaxcontroltoolkit.com
[解决办法]
Winform
在工具箱里有ProgressBar
[解决办法]

C# code
   Cursor = Cursors.WaitCursor;    //进度条FROM    waiting wt = new waiting();    new Thread(new ThreadStart(delegate     {                if (!wt.IsDisposed && !wt.Disposing) wt.ShowDialog();     })).Start();    ///    ///数据查询过程    ///    if (wt.InvokeRequired)            {                wt.Invoke(new MethodInvoker(delegate                {                    wt.Dispose();                }));            }            else            {                wt.Dispose();                wt.Close();            }     Cursor = Cursors.Arrow;
[解决办法]
探讨
忘了说了 Winform

[解决办法]
探讨
忘了说了 Winform

[解决办法]
C# code
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 delegate void CloseFunction();    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();            this.progressBar1.Maximum = 100;            this.thisTimer = new System.Windows.Forms.Timer();            this.thisTimer.Interval = 1000;            this.thisTimer.Tick += new EventHandler(thisTimer_Tick);            this.thisTimer.Start();            Thread thd = new Thread(new ParameterizedThreadStart(GetData ));            thd.Start();                   }        void thisTimer_Tick(object sender, EventArgs e)        {            progressBar1.PerformStep();        }        private void GetData( object o )        {            Thread.Sleep(100);            thisTimer.Stop();            this.Invoke( new CloseFunction( this.Close ) );        }        private System.Windows.Forms.Timer thisTimer;    }}  using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsApplication2{    public partial class MainFrame : Form    {        public MainFrame()        {            Form1 form1 = new Form1();            form1.ShowDialog();            InitializeComponent();        }        private void MainFrame_Load(object sender, EventArgs e)        {            string mPath=Application.StartupPath;            axWindowsMediaPlayer1.URL = mPath + "\\Voice\\1.mp3";            axWindowsMediaPlayer1.Ctlcontrols.play();        }    }}
[解决办法]
lz是想调用系统默认复制文件的那个对话框吧,2个文件夹之间一张纸飞来飞去的那个。。。。

C#调用系统的复制、移动、删除文件对话框
http://blog.csdn.net/herojams/archive/2009/01/05/3715247.aspx
[解决办法]
HTML code
对于一个进度条,无碍乎是最小最大值,以及当前值等一些重要的属性,至于方法,用得较多的是PerformStep()和PerformClick()之类的。代码如下:        private void btnRun_Click(object sender, EventArgs e)        {            btnRun.Enabled = false;            if (txtBoxTarget.Text.Equals(String.Empty) || txtBoxTimes.Text.Equals(String.Empty))            {                MessageBox.Show("请输入连接的URL和连接次数!", "提示",                    MessageBoxButtons.OK, MessageBoxIcon.Information);                return;            }            int length = Int32.Parse(txtBoxTimes.Text.Trim());            string url = txtBoxTarget.Text.Trim();            double process = 0;            int show = 0;     DateTime rightNow = DateTime.Now;            DateTime end;            TimeSpan interval;            toolStripStatusLabel.Text = "连接中";            progressBar.Visible = true;            progressBar.Minimum = 0;            progressBar.Maximum = length;     for (int i = 1; i <= length; i++)            {                try                {             // 这两句是连接某个网页的。                    WebRequest myRequest = WebRequest.Create(url);                    WebResponse myResponse = myRequest.GetResponse();                    myResponse.Close();                }                catch                {                    txtBoxReport.Text = "网络连接有误!";                    return;                }                progressBar.PerformStep();                process = i / length;                show = (int)process * 100;            }            progressBar.Visible = false;            toolStripStatusLabel.Text = "已就绪";            txtBoxReport.Text = "连接 " + url + " " + length + "次。";            end = DateTime.Now;            interval = end - rightNow;            txtBoxReport.Text += "\r\n共耗时" + interval.TotalMilliseconds + "毫秒。";            btnRun.Enabled = true;        } 


[解决办法]

C# code
public void createNewRecords(){   // Sets the progress bar's Maximum property to   // the total number of records to be created.   progressBar1.Maximum = 20;   // Creates a new record in the dataset.   // NOTE: The code below will not compile, it merely   // illustrates how the progress bar would be used.   CustomerRow anyRow = DatasetName.ExistingTable.NewRow();   anyRow.FirstName = "Stephen";   anyRow.LastName = "James";   ExistingTable.Rows.Add(anyRow);   // Increases the value displayed by the progress bar.   progressBar1.Value += 1;   // Updates the label to show that a record was read.   label1.Text = "Records Read = " + progressBar1.Value.ToString();}如果要显示按固定时间间隔增长的进度,则可以设置该值,然后调用方法,使 ProgressBar 控件的值按该时间间隔递增。对于计时器以及其他一些您无法以整体的百分比测量进度的方案,这是非常有用的。 使进度栏按固定值递增设置 ProgressBar 控件的 Minimum 和 Maximum 值。将控件的 Step 属性设置为一个整数,该整数代表进度栏的显示值递增的数量。 调用 PerformStep 方法,使显示值按 Step 属性中设置的数量进行更改。 下面的代码示例说明进度栏如何维护复制操作中的文件计数。 在下面的示例中,当每个文件读入内存时,进度栏和标签都会相应地更新,以反映读取的文件总数。该示例要求窗体有一个 Label 控件和一个 ProgressBar 控件。public void loadFiles(){   // Sets the progress bar's minimum value to a number representing   // no operations complete -- in this case, no files read.   progressBar1.Minimum = 0;   // Sets the progress bar's maximum value to a number representing   // all operations complete -- in this case, all five files read.   progressBar1.Maximum = 5;   // Sets the Step property to amount to increase with each iteration.   // In this case, it will increase by one with every file read.   progressBar1.Step = 1;   // Uses a for loop to iterate through the operations to be   // completed. In this case, five files are to be copied into memory,   // so the loop will execute 5 times.   for (int i = 0; i <= 4; i++)   {      // Inserts code to copy a file      progressBar1.PerformStep();      // Updates the label to show that a file was read.      label1.Text = "# of Files Read = " + progressBar1.Value.ToString();   }}最后,可以使进度栏的显示值每次递增的数量都是唯一的。这在您记录一系列唯一的操作时非常有用,例如将不同大小的文件写入硬盘,或者按整体的百分比测量进度。 使进度栏按动态值递增设置 ProgressBar 控件的 Minimum 和 Maximum 值。调用 Increment 方法,使显示值按指定的整数进行更改。 下面的代码示例说明在复制操作期间,进度栏如何计算已使用的磁盘空间量。 在下面的示例中,当每个文件写入硬盘时,进度栏和标签都会相应地更新,以反映可用的硬盘空间量。该示例要求窗体有一个 Label 控件和一个 ProgressBar 控件。 public void readFiles(){   // Sets the progress bar's minimum value to a number    // representing the hard disk space before the files are read in.   // You will most likely have to set this using a system call.   // NOTE: The code below is meant to be an example and    // will not compile.   progressBar1.Minimum = AvailableDiskSpace();   // Sets the progress bar's maximum value to a number    // representing the total hard disk space.   // You will most likely have to set this using a system call.   // NOTE: The code below is meant to be an example    // and will not compile.   progressBar1.Maximum = TotalDiskSpace();   // Uses a for loop to iterate through the operations to be   // completed. In this case, five files are to be written   // to the disk, so it will execute the loop 5 times.   for (int i = 1; i<= 5; i++)   {      // Insert code to read a file into memory and update file size.      // Increases the progress bar's value based on the size of       // the file currently being written.      progressBar1.Increment(FileSize);      // Updates the label to show available drive space.      label1.Text = "Current Disk Space Used = " + progressBar1.Value.ToString();   }}
[解决办法]
//例: 计算Fibonacci数列,并实时滚动进度条
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.ComponentModel;

class FibonacciNumber : Form
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new FibonacciNumber());


}

private StatusStrip progressStatusStrip;
private ToolStripProgressBar toolStripProgressBar;
private NumericUpDown requestedCountControl;
private Button goButton;
private TextBox outputTextBox;
private BackgroundWorker backgroundWorker;
private ToolStripStatusLabel toolStripStatusLabel;
private int requestedCount;

public FibonacciNumber()
{
Text = "Fibonacci";

// Prepare the StatusStrip.
progressStatusStrip = new StatusStrip();
toolStripProgressBar = new ToolStripProgressBar();
toolStripProgressBar.Enabled = false;
toolStripStatusLabel = new ToolStripStatusLabel();
progressStatusStrip.Items.Add(toolStripProgressBar);
progressStatusStrip.Items.Add(toolStripStatusLabel);

FlowLayoutPanel flp = new FlowLayoutPanel();
flp.Dock = DockStyle.Top;

Label beforeLabel = new Label();
beforeLabel.Text = "Calculate the first ";
beforeLabel.AutoSize = true;
flp.Controls.Add(beforeLabel);
requestedCountControl = new NumericUpDown();
requestedCountControl.Maximum = 1000;
requestedCountControl.Minimum = 1;
requestedCountControl.Value = 100;
flp.Controls.Add(requestedCountControl);
Label afterLabel = new Label();
afterLabel.Text = "Numbers in the Fibonacci sequence.";
afterLabel.AutoSize = true;
flp.Controls.Add(afterLabel);

goButton = new Button();
goButton.Text = "&Go";
goButton.Click += new System.EventHandler(button1_Click);
flp.Controls.Add(goButton);

outputTextBox = new TextBox();
outputTextBox.Multiline = true;
outputTextBox.ReadOnly = true;
outputTextBox.ScrollBars = ScrollBars.Vertical;
outputTextBox.Dock = DockStyle.Fill;

Controls.Add(outputTextBox);
Controls.Add(progressStatusStrip);
Controls.Add(flp);

backgroundWorker = new BackgroundWorker();
backgroundWorker.WorkerReportsProgress = true;
backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);

}

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
// This method will run on a thread other than the UI thread.
// Be sure not to manipulate any Windows Forms controls created
// on the UI thread from this method.
backgroundWorker.ReportProgress(0, "Working...");
Decimal lastlast = 0;
Decimal last = 1;
Decimal current;
if (requestedCount >= 1)
{ AppendNumber(0); }
if (requestedCount >= 2)
{ AppendNumber(1); }
for (int i = 2; i < requestedCount; ++i)
{
// Calculate the number.
checked { current = lastlast + last; }
// Introduce some delay to simulate a more complicated calculation.
System.Threading.Thread.Sleep(100);
AppendNumber(current);
backgroundWorker.ReportProgress((100 * i) / requestedCount, "Working...");
// Get ready for the next iteration.
lastlast = last;
last = current;
}


backgroundWorker.ReportProgress(100, "Complete!");
}

private delegate void AppendNumberDelegate(Decimal number);
private void AppendNumber(Decimal number)


{
if (outputTextBox.InvokeRequired)
{ outputTextBox.Invoke(new AppendNumberDelegate(AppendNumber), number); }
else
{ outputTextBox.AppendText(number.ToString("N0") + Environment.NewLine); }
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
toolStripProgressBar.Value = e.ProgressPercentage;
toolStripStatusLabel.Text = e.UserState as String;
}

private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error is OverflowException)
{ outputTextBox.AppendText(Environment.NewLine + "**OVERFLOW ERROR, number is too large to be represented by the decimal data type**"); }
toolStripProgressBar.Enabled = false;
requestedCountControl.Enabled = true;
goButton.Enabled = true;

}

private void button1_Click(object sender, EventArgs e)
{
goButton.Enabled = false;
toolStripProgressBar.Enabled = true;
requestedCount = (int)requestedCountControl.Value;
requestedCountControl.Enabled = false;
outputTextBox.Clear();
backgroundWorker.RunWorkerAsync();
}
}

[解决办法]

C# code
// 你是 Winform 么?// 你添加一个窗体类,命名为 ProgressForm,会给你自动生成一个框架,大体如下,然后往里面添代码public partial class ProgressForm : Form{    public ProgressForm()    {        InitializeComponent();    }    .........      // [color=#FF0000](1)[/color]}// 下面重写它的Loaded 事件,在属性对话框里面双击该事件,然后补代码:private void ProgressForm_Loaded ( object sender, EventArgs e ){    this.__myProgressBar.Minimum = 0;    this.__myProgressBar.Maximum = 100;    this.__myProgressBar.Value = 1;    this.__myProgressBar.Step = 1;    this.__myProgressBar.PerformStep();}// 你可以在可视化设计板里面往窗体上拖上一个 ProgressBar,设置它的属性,或者在窗体的Loaded事件里面写好。
[解决办法]
强大. 标记
[解决办法]
up
[解决办法]
探讨
引用:
lz是想调用系统默认复制文件的那个对话框吧,2个文件夹之间一张纸飞来飞去的那个。。。。

C#调用系统的复制、移动、删除文件对话框
http://blog.csdn.net/herojams/archive/2009/01/05/3715247.aspx


我不是要调用系统的

我只想做这么一个东西

[解决办法]
探讨
引用:
lz是想调用系统默认复制文件的那个对话框吧,2个文件夹之间一张纸飞来飞去的那个。。。。

C#调用系统的复制、移动、删除文件对话框
http://blog.csdn.net/herojams/archive/2009/01/05/3715247.aspx


我不是要调用系统的

我只想做这么一个东西

[解决办法]

我什么时候把它放到FOR里面了……

再说,那只是示例代码,表达一下思想而已。
[解决办法]
参考
参考
参考
[解决办法]
楼主问题解决了没有啊?
你试下这个吧
拖个进度条控件ProgressBar
主要代码
using System.Threading;

form_load里面写
for(int i=0;i<5;i++)
{
Thread.CurrentThread.Join(500);
this.progressBar1.Performstep();
}
[解决办法]
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 WindowsApplication1
{
public partial class Form1 : Form


{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
Thread.CurrentThread.Join(1000);
this.progressBar1.PerformStep();
}
}
}
}
[解决办法]
晕,那么复杂,不用多线程也可以阿~~


C# code
pgsBar.Maxium=99;for (int i=0;i<100;i++){  pgsBar.Value=i;  Thread.Sleep(100);  Application.DoEvents();}
[解决办法]
.....
[解决办法]
up
[解决办法]
http://www.cnblogs.com/yuxuanji/articles/1095011.html

[解决办法]
学习一下
[解决办法]
如果要异步的话,貌似可以考虑使用BackgroudWorker控件...
[解决办法]
探讨
顶一下,上面的例子搞了半天没搞出来啊.........继续

[解决办法]
C# code
this.backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);this.backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);            this.backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)        {            BackgroundWorker worker = sender as BackgroundWorker;MethodA(worker,e); if (worker.CancellationPending)            {                e.Cancel = true;            }        }        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)        {            this.progressPercent.Value = e.ProgressPercentage;        }        private void MethodA(BackgroundWorker worker, DoWorkEventArgs e){            int totalPercent =100;            int perComplete = 0;                    if (perComplete != (int)(((float)i / totalPercent) * 100))                    {                        perComplete = (int)(((float)i / totalPercent) * 100);                        worker.ReportProgress(perComplete);                    }}
[解决办法]
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
Thread.CurrentThread.Join(500);
this.progressBar1.PerformStep();
}
}
效果明显些
[解决办法]
C# code
进度条是一个软件人性化考虑之一,他给用户的感觉就是程序内部在不停的动作,执行到了什么程度,而不是整个界面僵死,以至于用户不知道程序在做什么!  看了好几个WinForm程序了,发现他们对进度条的处理完全失去了进度条的作用。他们都是采用Timer来处理,在线程结束的时候,直接赋值进度条达到100%。和我以前做WebForm程序的时候完全不一样,做WebForm程序的时候,进度条是根据总体数据和每步执行后而计算和更新的。在看了这几个WinForm程序后,我在想:是否所有WinForm程序,在进度条的处理上都不能保证实时进度显示?  其实用Timer来处理,不停的更新进度条只是程序作者偷懒的方法。当然这样的好处就是可以简单化处理进度条,代码量少,不易出错,调试方便。  还有一种方法,就是可以及时更新进度条的数据的。那就是采用事件驱动机制,在子线程中监视复杂处理过程中的设定的事件,及时更新!直接看代码:程序代码using System;using System.ComponentModel;using System.Windows.Forms;namespace WindowsApplication1{     /// <summary>     /// Form1 类     /// </summary>     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();         }         private void button1_Click(object sender, EventArgs e)         {             //用子线程工作             new System.Threading.Thread(new System.Threading.ThreadStart(StartDownload)).Start();         }         //开始下载         public void StartDownload()         {             Downloader downloader = new Downloader();             downloader.onDownLoadProgress += new Downloader.dDownloadProgress(downloader_onDownLoadProgress);             downloader.Start();         }         //同步更新UI         void downloader_onDownLoadProgress(long total, long current)         {             if (this.InvokeRequired)             {                 this.Invoke(new Downloader.dDownloadProgress(downloader_onDownLoadProgress), new object[] { total, current });             }             else             {                 this.progressBar1.Maximum = (int)total;                 this.progressBar1.Value = (int)current;             }         }     }     /// <summary>     /// 下载类(您的复杂处理类)     /// </summary>     public class Downloader     {         //委托         public delegate void dDownloadProgress(long total,long current);         //事件         public event dDownloadProgress onDownLoadProgress;         //开始模拟工作         public void Start()         {             for (int i = 0; i < 100; i++)             {                 if (onDownLoadProgress != null)                     onDownLoadProgress(100, i);                 System.Threading.Thread.Sleep(100);             }         }     }}=================================ling========================================delegate object dlExecuteQuery(); private void button1_Click(object sender, EventArgs e) { dlExecuteQuery de=new dlExecuteQuery(this.Query()); IAsyncResult ir = de.BeginInvoke(null, null);Form f=new Form() f.ShowDialog(this); Application.DoEvents(); while (!ir.IsCompleted) { Application.DoEvents(); } object obj = de.EndInvoke(ir); f.Close(); }private object Query() { //长时间的操作 } 


[解决办法]
学习学习了哈
[解决办法]
up,
[解决办法]
关注


.


[color=#FFFFFF]人力资源[/color]

读书人网 >C#

热点推荐