ProgressBarForm
public partial class ProgressBarForm : Form { private Panel panel1 = new System.Windows.Forms.Panel(); private ProgressBar progressBar1 = new System.Windows.Forms.ProgressBar(); public ProgressBarForm() { InitializeComponent(); InitializeComponent2(); } public int LoadProgressBarRate(float currentNum, float totalCount) { float add = 100 / totalCount; var currentBar = (int)Math.Ceiling(add * currentNum); progressBar1.Value = currentBar >= 0 && currentBar <= 100 ? currentBar : 100; Application.DoEvents(); return currentNum == totalCount ? 1 : 0; } private void InitializeComponent2() { this.panel1.SuspendLayout(); this.SuspendLayout(); // // panel1 // this.panel1.Controls.Add(this.progressBar1); this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(1000, 50); this.panel1.TabIndex = 0; // // progressBar1 // this.progressBar1.Dock = System.Windows.Forms.DockStyle.Fill; this.progressBar1.Location = new System.Drawing.Point(0, 0); this.progressBar1.Name = "progressBar1"; this.progressBar1.Size = new System.Drawing.Size(1000, 50); this.progressBar1.TabIndex = 0; // // ProgressBarForm // this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 21F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1000, 50); this.Controls.Add(this.panel1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "ProgressBarForm"; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "正在传输"; this.panel1.ResumeLayout(false); this.ResumeLayout(false); } }