winForm 实现加栽窗体显示进度条或者显示"数据加栽中....." 我知道这个控件可以实现,但是我想看看具体的 代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;using System.Threading;namespace WindowsApplication1{ public class Form1 : Form { private System.ComponentModel.BackgroundWorker backgroundWorker1; private StatusStrip statusStrip1; private ToolStripProgressBar toolStripProgressBar1; private ToolStripStatusLabel toolStripStatusLabel1; private Button button2; private Button button1; public Form1() : base() { InitializeComponent(); } private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar(); this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); this.button2 = new System.Windows.Forms.Button(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(12, 12); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 0; this.button1.Text = "Load"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // backgroundWorker1 // this.backgroundWorker1.WorkerReportsProgress = true; this.backgroundWorker1.WorkerSupportsCancellation = true; this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork); this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted); this.backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged); // // statusStrip1 // this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripProgressBar1, this.toolStripStatusLabel1}); this.statusStrip1.Location = new System.Drawing.Point(0, 244); this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.Size = new System.Drawing.Size(292, 22); this.statusStrip1.TabIndex = 1; this.statusStrip1.Text = "statusStrip1"; // // toolStripProgressBar1 // this.toolStripProgressBar1.Name = "toolStripProgressBar1"; this.toolStripProgressBar1.Size = new System.Drawing.Size(100, 16); // // toolStripStatusLabel1 // this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; this.toolStripStatusLabel1.Size = new System.Drawing.Size(175, 17); this.toolStripStatusLabel1.Spring = true; // // button2 // this.button2.Location = new System.Drawing.Point(134, 12); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 23); this.button2.TabIndex = 2; this.button2.Text = "Cancel"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // Form1 // this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.button2); this.Controls.Add(this.statusStrip1); this.Controls.Add(this.button1); this.Name = "Form1"; this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { toolStripStatusLabel1.Text = "Please wait ............"; for (int index = 1; index < 100; index++) { Thread.Sleep(100); if (backgroundWorker1.CancellationPending) { e.Cancel = true; break; } backgroundWorker1.ReportProgress(index); } } private void backgroundWorker1_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) { try { toolStripProgressBar1.Value = e.ProgressPercentage; } catch (Exception ) { } } private void backgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) { toolStripProgressBar1.Value = 0; toolStripStatusLabel1.Text = string.Empty; } private void button1_Click(object sender, EventArgs e) { backgroundWorker1.RunWorkerAsync(); } private void button2_Click(object sender, EventArgs e) { if (backgroundWorker1.IsBusy) //check backgroundWorker state { backgroundWorker1.CancelAsync(); } } }} 'InstallUtil' 不是内部或外部命令,也不是可运行的程序 关于C#里线程睡眠的问题!! 0001+1怎么才能等于0002啊? 外网如何访问,我局域网内某台机子的服务。可以吗。 如何在关机前调用自编写WINDOWS服务程序 如何屏蔽打印web页自带的默认网址 FlowLayoutPanel问题!!! C#中的ACCESS连接问题 如何启动进程性能计数器,大虾帮忙,谢谢!!! 关于C#学习书的选择???? c# 关于程序导出 数据库的处理问题 如何自动读取光盘内文件夹名称
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication1
{
public class Form1 : Form
{
private System.ComponentModel.BackgroundWorker backgroundWorker1;
private StatusStrip statusStrip1;
private ToolStripProgressBar toolStripProgressBar1;
private ToolStripStatusLabel toolStripStatusLabel1;
private Button button2;
private Button button1; public Form1() : base() { InitializeComponent(); } private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar();
this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
this.button2 = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "Load";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// backgroundWorker1
//
this.backgroundWorker1.WorkerReportsProgress = true;
this.backgroundWorker1.WorkerSupportsCancellation = true;
this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted);
this.backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged);
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripProgressBar1,
this.toolStripStatusLabel1});
this.statusStrip1.Location = new System.Drawing.Point(0, 244);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(292, 22);
this.statusStrip1.TabIndex = 1;
this.statusStrip1.Text = "statusStrip1";
//
// toolStripProgressBar1
//
this.toolStripProgressBar1.Name = "toolStripProgressBar1";
this.toolStripProgressBar1.Size = new System.Drawing.Size(100, 16);
//
// toolStripStatusLabel1
//
this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
this.toolStripStatusLabel1.Size = new System.Drawing.Size(175, 17);
this.toolStripStatusLabel1.Spring = true;
//
// button2
//
this.button2.Location = new System.Drawing.Point(134, 12);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2;
this.button2.Text = "Cancel";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button2);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout(); } private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
toolStripStatusLabel1.Text = "Please wait ............";
for (int index = 1; index < 100; index++)
{
Thread.Sleep(100);
if (backgroundWorker1.CancellationPending)
{
e.Cancel = true;
break;
}
backgroundWorker1.ReportProgress(index);
}
} private void backgroundWorker1_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
{
try
{
toolStripProgressBar1.Value = e.ProgressPercentage;
}
catch (Exception ) { }
} private void backgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
toolStripProgressBar1.Value = 0;
toolStripStatusLabel1.Text = string.Empty;
} private void button1_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
} private void button2_Click(object sender, EventArgs e)
{
if (backgroundWorker1.IsBusy) //check backgroundWorker state
{
backgroundWorker1.CancelAsync();
}
}
}
}