ProgressStatus.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace SAGA.DotNetUtils.WinForms
  6. {
  7. public class ProgressStatus : Form
  8. {
  9. private IContainer components;
  10. private bool m_isFinished;
  11. private string m_textString;
  12. private ProgressBar progressBar1;
  13. public ProgressStatus(int intMaxValue) : this(intMaxValue, string.Empty)
  14. {
  15. }
  16. public ProgressStatus(int intMaxValue, string strText)
  17. {
  18. this.m_textString = string.Empty;
  19. this.InitializeComponent();
  20. this.Text = strText;
  21. this.m_textString = strText;
  22. this.progressBar1.Minimum = 0;
  23. this.progressBar1.Value = 0;
  24. this.progressBar1.Maximum = Math.Max(1, intMaxValue);
  25. }
  26. protected override void Dispose(bool disposing)
  27. {
  28. if (disposing && (this.components != null))
  29. {
  30. this.components.Dispose();
  31. }
  32. base.Dispose(disposing);
  33. }
  34. public void Finish()
  35. {
  36. this.m_isFinished = true;
  37. this.progressBar1.Value = this.progressBar1.Maximum;
  38. base.Visible = false;
  39. base.Close();
  40. }
  41. private void InitializeComponent()
  42. {
  43. this.progressBar1 = new ProgressBar();
  44. base.SuspendLayout();
  45. this.progressBar1.Location = new Point(9, 0x11);
  46. this.progressBar1.Name = "progressBar1";
  47. this.progressBar1.Size = new Size(0x1c8, 0x16);
  48. this.progressBar1.TabIndex = 0;
  49. base.AutoScaleDimensions = new SizeF(6f, 12f);
  50. base.AutoScaleMode = AutoScaleMode.Font;
  51. base.ClientSize = new Size(0x1da, 0x36);
  52. base.Controls.Add(this.progressBar1);
  53. base.MaximizeBox = false;
  54. base.MinimizeBox = false;
  55. base.Name = "ProgressStatus";
  56. base.ShowIcon = false;
  57. base.ShowInTaskbar = false;
  58. base.StartPosition = FormStartPosition.CenterScreen;
  59. base.TopMost = true;
  60. base.FormClosing += new FormClosingEventHandler(this.ProgressStatus_FormClosing);
  61. base.Load += new EventHandler(this.ProgressStatus_Load);
  62. base.ResumeLayout(false);
  63. }
  64. private void ProgressStatus_FormClosing(object sender, FormClosingEventArgs e)
  65. {
  66. if (!this.m_isFinished)
  67. {
  68. e.Cancel = true;
  69. }
  70. }
  71. private void ProgressStatus_Load(object sender, EventArgs e)
  72. {
  73. if (this.Text.Length <= 0)
  74. {
  75. this.Text = "正在处理数据,请稍候... ";
  76. this.m_textString = this.Text;
  77. }
  78. }
  79. public void UpdateStatus()
  80. {
  81. int intValue = this.progressBar1.Value;
  82. if (intValue < 0)
  83. {
  84. intValue = 0;
  85. }
  86. intValue++;
  87. this.UpdateStatus(intValue);
  88. }
  89. public void UpdateStatus(int intValue)
  90. {
  91. this.m_isFinished = false;
  92. if (intValue > this.progressBar1.Maximum)
  93. {
  94. intValue = this.progressBar1.Maximum;
  95. }
  96. this.progressBar1.Value = intValue;
  97. if (!base.Visible)
  98. {
  99. base.Visible = true;
  100. }
  101. this.Text = string.Concat(new object[] { this.m_textString, " 已完成 ", Math.Round((double) ((((double) intValue) / ((double) this.progressBar1.Maximum)) * 100.0), 2), "%" });
  102. if ((intValue > 10) && ((intValue % 10) == 0))
  103. {
  104. Application.DoEvents();
  105. }
  106. else if (this.progressBar1.Maximum < 20)
  107. {
  108. this.Refresh();
  109. Application.DoEvents();
  110. }
  111. }
  112. }
  113. }