Form_jdt.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System;
  2. using System.Threading;
  3. using System.Windows.Forms;
  4. namespace LJLib.Jdt
  5. {
  6. public partial class Form_jdt : Form, IJdt, IDisposable
  7. {
  8. public static Form_jdt NewWin()
  9. {
  10. Form_jdt rslt = new Form_jdt();
  11. ThreadPool.QueueUserWorkItem(rslt.ShowJdt);
  12. do
  13. {
  14. Thread.Sleep(100);
  15. } while (!rslt.isShown);
  16. return rslt;
  17. }
  18. private Form_jdt()
  19. {
  20. InitializeComponent();
  21. this.closeJdt = this.CloseJdt;
  22. this.dispose = this.Dispose;
  23. this.acceptTotal = this.AcceptTotal;
  24. this.inc = this.Inc;
  25. this.setMsg = this.SetMsg;
  26. this.ole_test = this.label1.Text;
  27. }
  28. public bool isShown = false;
  29. private void ShowJdt(object state)
  30. {
  31. this.ShowDialog();
  32. }
  33. public void CloseJdt()
  34. {
  35. if (this.InvokeRequired)
  36. {
  37. this.Invoke(this.closeJdt);
  38. }
  39. else
  40. {
  41. if (this.isShown)
  42. {
  43. this.Close();
  44. this.isShown = false;
  45. }
  46. }
  47. }
  48. private string ole_test;
  49. public void AcceptTotal(int total)
  50. {
  51. if (this.InvokeRequired)
  52. {
  53. this.Invoke(this.acceptTotal, new object[] { total });
  54. }
  55. else
  56. {
  57. this.progressBar1.Maximum = total;
  58. this.Inc(0);
  59. this.SetMsg(this.ole_test);
  60. }
  61. }
  62. public void Inc(int value)
  63. {
  64. if (this.InvokeRequired)
  65. {
  66. this.Invoke(this.inc, new object[] { value });
  67. }
  68. else
  69. {
  70. if (value < this.progressBar1.Minimum)
  71. {
  72. value = this.progressBar1.Minimum;
  73. }
  74. if (value > this.progressBar1.Maximum)
  75. {
  76. value = this.progressBar1.Maximum;
  77. }
  78. this.progressBar1.Value = value;
  79. float progress = (float)this.progressBar1.Value / this.progressBar1.Maximum * 100;
  80. this.label2.Text = progress.ToString("####0.0") + "%";
  81. }
  82. }
  83. public void SetMsg(string value)
  84. {
  85. if (this.InvokeRequired)
  86. {
  87. this.Invoke(this.setMsg, new object[] { value });
  88. }
  89. else
  90. {
  91. this.label1.Text = value;
  92. }
  93. }
  94. private delegate void Delegate1();
  95. private Delegate1 closeJdt;
  96. private Delegate1 dispose;
  97. private delegate void Delegate2(int value);
  98. private Delegate2 acceptTotal;
  99. private Delegate2 inc;
  100. private delegate void Delegate3(string value);
  101. private Delegate3 setMsg;
  102. private void Form_jdt_Shown(object sender, EventArgs e)
  103. {
  104. this.Focus();
  105. isShown = true;
  106. }
  107. #region IDisposable 成员
  108. void IDisposable.Dispose()
  109. {
  110. if (this.InvokeRequired)
  111. {
  112. this.Invoke(this.dispose);
  113. }
  114. else
  115. {
  116. CloseJdt();
  117. base.Dispose();
  118. }
  119. }
  120. #endregion
  121. }
  122. }