⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 progressform.cs

📁 C#自定义查询控件
💻 CS
字号:
using System;
using System.Windows.Forms;
using System.Drawing;

namespace CommonComponent.CommonIE
{
	/// <summary>
	/// 
	/// </summary>
	public class ProgressForm : System.Windows.Forms.Form
	{
		public ProgressForm()
		{
			InitializeComponent();
			// 
			// TODO: Add constructor logic here
			//
		}

		public DateTime BeginDate;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.ProgressBar progressBar1;
		public static ProgressForm fmProgress;

		public static void CreateProgress(string Title, int MaxProgress)
		{
			if (fmProgress == null) 
				fmProgress = new ProgressForm();

			fmProgress.label1.Text = Title;
			fmProgress.progressBar1.Maximum = MaxProgress;
			fmProgress.progressBar1.Value = 0;
			fmProgress.BeginDate = System.DateTime.Now;
			fmProgress.Show();
		}

		public static void UpdateProgress(int Position)
		{
			double Delay1,Percent1;
			Int32 i;
			String timeStr;

			timeStr = "";
			if (fmProgress != null)
			{
				fmProgress.progressBar1.Value = Position;
				Percent1 = (double)Position / (double)fmProgress.progressBar1.Maximum;

				
				fmProgress.label3.Text = Convert.ToInt32(Percent1 * 100.0).ToString() + "%";

				Delay1 = (DateTime.Now - fmProgress.BeginDate).TotalHours * 24.0 / Percent1 * (1- Percent1);

			///	Decimal.
				

				i = Convert.ToInt32( Math.Floor(Delay1));
				if (i > 0)
					timeStr = timeStr + i.ToString()+"时";

				Delay1 = (Delay1 - i ) * 60;

				i = Convert.ToInt32( Math.Floor(Delay1));
				if (i > 0)
					timeStr = timeStr + i.ToString()+"分";

				Delay1 = (Delay1 - i ) * 60;

				i = Convert.ToInt32( Math.Floor(Delay1));
				if (i > 0)
					timeStr = timeStr + i.ToString()+"秒";
				else

					timeStr = timeStr + "0秒";
				
				fmProgress.label5.Text = timeStr;
				fmProgress.Update();
			}
		
		}

		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.progressBar1 = new System.Windows.Forms.ProgressBar();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(19, 8);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(377, 28);
			this.label1.TabIndex = 0;
			this.label1.Text = "正在输入文件...";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(339, 48);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(55, 13);
			this.label2.TabIndex = 1;
			this.label2.Text = "已经完成";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(282, 48);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(39, 13);
			this.label3.TabIndex = 2;
			this.label3.Text = "0%";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(20, 48);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(64, 13);
			this.label4.TabIndex = 3;
			this.label4.Text = "剩余时间";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(99, 48);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(133, 13);
			this.label5.TabIndex = 4;
			this.label5.Text = "label5";
			// 
			// progressBar1
			// 
			this.progressBar1.Location = new System.Drawing.Point(12, 70);
			this.progressBar1.Name = "progressBar1";
			this.progressBar1.Size = new System.Drawing.Size(391, 16);
			this.progressBar1.TabIndex = 5;
			this.progressBar1.Value = 50;
			// 
			// ProgressForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(414, 94);
			this.Controls.Add(this.progressBar1);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Name = "ProgressForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.ResumeLayout(false);

		}

		public static void DeleteProgress()
		{
			if (fmProgress != null)
			{
				fmProgress.Dispose();
				fmProgress = null;
			}
		
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -