更新时间:2023-12-06 10:49:52
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, System.EventArgs e)
{
// Start the BackgroundWorker.
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 1; i <= 100; i++)
{
// Wait 100 milliseconds.
Thread.Sleep(100);
// Report progress.
backgroundWorker1.ReportProgress(i);
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
// Change the value of the ProgressBar to the BackgroundWorker progress.
progressBar1.Value = e.ProgressPercentage;
// Set the text.
this.Text = e.ProgressPercentage.ToString();
}
}
}
更多详情访问下面的网页...
http://www.dotnetperls.com/progressbar [ ^ ]
这就是我在dotnet上做的事情3.5
This is what i do on dotnet 3.5
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private delegate void progressDelegate(string progress);
private void Form1_Load(object sender, System.EventArgs e)
{
// Start the BackgroundWorker.
ProgressBar1.Visible = true;
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i <= 50000; i++)
{
progressDelegate m_UpdateText = null;
m_UpdateText = new progressDelegate(progress1);
this.Invoke(m_UpdateText, i.ToString());
}
}
private void progress1(string progress)
{
this.Text = progress;
ProgressBar1.Minimum = 0;
ProgressBar1.Maximum = 50000;
ProgressBar1.Value = Convert.ToInt32(progress);
}
private void BackgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
Interaction.MsgBox("Done proccessing");
this.Text = "Done";
ProgressBar1.Visible = false;
}
}
private void btn_Submit_Click(object sender,EventArgs e)
{
Progressbar1.Visible = True;
//这里你的代码
}
private void btn_Submit_Click(object sender, EventArgs e)
{
Progressbar1.Visible=True;
//here ur code
}