c#做WinFro进度条(ProgressBar)怎么弄?
this.progressBar1.Maximum = table.Rows.Count;
for (int i = 0; i < table.Rows.Count; i++)
{
this.progressBar1.Value = i;
System.Threading.Thread.Sleep(100);
}
现在想通lable.text显示已经发送了多少的条,和还有多少没有发送,请问该怎么写? ProgressBar --------------------编程问答-------------------- label1.Text = "已发送:'+i.ToString()+",还剩"+(table.Rows.Count-i).ToString;
Application.DoEvents(); --------------------编程问答--------------------
这个只能在现实完才能看到 我是想没成功一条都会显示 跟着进度的进度一样 --------------------编程问答-------------------- this.progressBar1.Maximum = table.Rows.Count;
for (int i = 0; i < table.Rows.Count; i++)
{
this.progressBar1.Value = i;
label1.Text = "已发送:'+i.ToString()+",还剩"+(table.Rows.Count-i).ToString;
Application.DoEvents();
} --------------------编程问答--------------------
--------------------编程问答--------------------
public partial class Form1 : Form { private delegate void ThreadWork(int i); Thread thread; public Form1() { InitializeComponent(); // CheckForIllegalCrossThreadCalls = false; } private void button1_Click(object sender, EventArgs e) { this.richTextBox1.Text = "程序开始:\r\n"; UpdateText(); } public void UpdateText() { thread = new Thread(new ThreadStart(CrossThreadFlush)); thread.IsBackground = true; thread.Start(); } private void CrossThreadFlush() { while (true) { //将sleep和无限循环放在等待异步的外面 for (int i = 1; i < 100; i++) { ThreadFunction(i); Thread.Sleep(500); } } } private void ThreadFunction(int i) { if (this.richTextBox1.InvokeRequired)//等待异步 { ThreadWork fc = new ThreadWork(ThreadFunction); // this.Invoke(fc);//通过代理调用刷新方法 this.Invoke(fc, new object[1] { i }); } else { this.richTextBox1.Text = string.Format("第{0}个\t{1:mm-ss}\r\n", i, DateTime.Now) + this.richTextBox1.Text; this.richTextBox1.Refresh(); } } }}--------------------编程问答-------------------- 参考一下这个!
--------------------编程问答--------------------
public partial class Form1 : Form--------------------编程问答-------------------- 看看msdn的例子吧http://msdn.microsoft.com/zh-cn/library/system.windows.controls.progressbar.aspx --------------------编程问答-------------------- 了解一下,这个组件backgroundWorker1
{
private delegate void ThreadWork(int i);
Thread thread;
public Form1()
{
InitializeComponent();
// CheckForIllegalCrossThreadCalls = false;
}
private void button1_Click(object sender, EventArgs e)
{
this.richTextBox1.Text = "程序开始:\r\n";
UpdateText();
}
public void UpdateText()
{
thread = new Thread(new ThreadStart(CrossThreadFlush));
thread.IsBackground = true;
thread.Start();
}
private void CrossThreadFlush()
{
while (true)
{
//将sleep和无限循环放在等待异步的外面
for (int i = 1; i < 100; i++)
{
ThreadFunction(i);
Thread.Sleep(500);
}
}
}
private void ThreadFunction(int i)
{
if (this.richTextBox1.InvokeRequired)//等待异步
{
ThreadWork fc = new ThreadWork(ThreadFunction);
// this.Invoke(fc);//通过代理调用刷新方法
this.Invoke(fc, new object[1] { i });
}
else
{
this.richTextBox1.Text = string.Format("第{0}个\t{1:mm-ss}\r\n", i, DateTime.Now) + this.richTextBox1.Text;
this.richTextBox1.Refresh();
}
}
}
http://blog.163.com/j_yd168/blog/static/4967972820092114269195/
完全适合你当前的需求. --------------------编程问答--------------------
可以了 非常感谢,
补充:.NET技术 , C#