| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Windows.Forms;
- namespace SAGA.DotNetUtils.WinForms
- {
- public class ProgressStatus : Form
- {
- private IContainer components;
- private bool m_isFinished;
- private string m_textString;
- private ProgressBar progressBar1;
- public ProgressStatus(int intMaxValue) : this(intMaxValue, string.Empty)
- {
- }
- public ProgressStatus(int intMaxValue, string strText)
- {
- this.m_textString = string.Empty;
- this.InitializeComponent();
- this.Text = strText;
- this.m_textString = strText;
- this.progressBar1.Minimum = 0;
- this.progressBar1.Value = 0;
- this.progressBar1.Maximum = Math.Max(1, intMaxValue);
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing && (this.components != null))
- {
- this.components.Dispose();
- }
- base.Dispose(disposing);
- }
- public void Finish()
- {
- this.m_isFinished = true;
- this.progressBar1.Value = this.progressBar1.Maximum;
- base.Visible = false;
- base.Close();
- }
- private void InitializeComponent()
- {
- this.progressBar1 = new ProgressBar();
- base.SuspendLayout();
- this.progressBar1.Location = new Point(9, 0x11);
- this.progressBar1.Name = "progressBar1";
- this.progressBar1.Size = new Size(0x1c8, 0x16);
- this.progressBar1.TabIndex = 0;
- base.AutoScaleDimensions = new SizeF(6f, 12f);
- base.AutoScaleMode = AutoScaleMode.Font;
- base.ClientSize = new Size(0x1da, 0x36);
- base.Controls.Add(this.progressBar1);
- base.MaximizeBox = false;
- base.MinimizeBox = false;
- base.Name = "ProgressStatus";
- base.ShowIcon = false;
- base.ShowInTaskbar = false;
- base.StartPosition = FormStartPosition.CenterScreen;
- base.TopMost = true;
- base.FormClosing += new FormClosingEventHandler(this.ProgressStatus_FormClosing);
- base.Load += new EventHandler(this.ProgressStatus_Load);
- base.ResumeLayout(false);
- }
- private void ProgressStatus_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (!this.m_isFinished)
- {
- e.Cancel = true;
- }
- }
- private void ProgressStatus_Load(object sender, EventArgs e)
- {
- if (this.Text.Length <= 0)
- {
- this.Text = "正在处理数据,请稍候... ";
- this.m_textString = this.Text;
- }
- }
- public void UpdateStatus()
- {
- int intValue = this.progressBar1.Value;
- if (intValue < 0)
- {
- intValue = 0;
- }
- intValue++;
- this.UpdateStatus(intValue);
- }
- public void UpdateStatus(int intValue)
- {
- this.m_isFinished = false;
- if (intValue > this.progressBar1.Maximum)
- {
- intValue = this.progressBar1.Maximum;
- }
- this.progressBar1.Value = intValue;
- if (!base.Visible)
- {
- base.Visible = true;
- }
- this.Text = string.Concat(new object[] { this.m_textString, " 已完成 ", Math.Round((double) ((((double) intValue) / ((double) this.progressBar1.Maximum)) * 100.0), 2), "%" });
- if ((intValue > 10) && ((intValue % 10) == 0))
- {
- Application.DoEvents();
- }
- else if (this.progressBar1.Maximum < 20)
- {
- this.Refresh();
- Application.DoEvents();
- }
- }
- }
- }
|