EraseProgress.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using NEROLib;
  7. namespace LYFZ.NeroDiscBurn.NET
  8. {
  9. /// <summary>
  10. /// Summary description for EraseProgress.
  11. /// </summary>
  12. public class EraseProgressForm : System.Windows.Forms.Form
  13. {
  14. private NeroDrive m_drive;
  15. private bool m_bQuick;
  16. private bool m_bShowResultDialog;
  17. private DateTime m_timeStart;
  18. private System.Timers.Timer m_timer;
  19. private int m_iErasingTime;
  20. private _INeroDriveEvents_OnDoneEraseEventHandler m_evOnDoneErase;
  21. private System.Windows.Forms.ProgressBar c_Progress;
  22. private System.Windows.Forms.Label c_ProgressPercent;
  23. private System.Windows.Forms.Label c_Caption;
  24. /// <summary>
  25. /// Required designer variable.
  26. /// </summary>
  27. private System.ComponentModel.Container components = null;
  28. public EraseProgressForm(NeroDrive drive, bool bQuick)
  29. {
  30. //
  31. // Required for Windows Form Designer support
  32. //
  33. InitializeComponent();
  34. m_drive = drive;
  35. m_bQuick = bQuick;
  36. m_bShowResultDialog = true;
  37. }
  38. public EraseProgressForm(NeroDrive drive, bool bQuick, bool bShowResultDialog)
  39. : this (drive, bQuick)
  40. {
  41. m_bShowResultDialog = bShowResultDialog;
  42. }
  43. /// <summary>
  44. /// Clean up any resources being used.
  45. /// </summary>
  46. protected override void Dispose( bool disposing )
  47. {
  48. if( disposing )
  49. {
  50. if(components != null)
  51. {
  52. components.Dispose();
  53. }
  54. }
  55. base.Dispose( disposing );
  56. }
  57. #region Windows Form Designer generated code
  58. /// <summary>
  59. /// Required method for Designer support - do not modify
  60. /// the contents of this method with the code editor.
  61. /// </summary>
  62. private void InitializeComponent()
  63. {
  64. this.c_Progress = new System.Windows.Forms.ProgressBar();
  65. this.c_ProgressPercent = new System.Windows.Forms.Label();
  66. this.c_Caption = new System.Windows.Forms.Label();
  67. this.SuspendLayout();
  68. //
  69. // c_Progress
  70. //
  71. this.c_Progress.Location = new System.Drawing.Point(10, 60);
  72. this.c_Progress.Name = "c_Progress";
  73. this.c_Progress.Size = new System.Drawing.Size(444, 25);
  74. this.c_Progress.TabIndex = 2;
  75. //
  76. // c_ProgressPercent
  77. //
  78. this.c_ProgressPercent.Location = new System.Drawing.Point(173, 34);
  79. this.c_ProgressPercent.Name = "c_ProgressPercent";
  80. this.c_ProgressPercent.Size = new System.Drawing.Size(59, 18);
  81. this.c_ProgressPercent.TabIndex = 1;
  82. this.c_ProgressPercent.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
  83. //
  84. // c_Caption
  85. //
  86. this.c_Caption.Location = new System.Drawing.Point(10, 9);
  87. this.c_Caption.Name = "c_Caption";
  88. this.c_Caption.Size = new System.Drawing.Size(384, 17);
  89. this.c_Caption.TabIndex = 0;
  90. this.c_Caption.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
  91. //
  92. // EraseProgressForm
  93. //
  94. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  95. this.ClientSize = new System.Drawing.Size(466, 96);
  96. this.ControlBox = false;
  97. this.Controls.Add(this.c_Caption);
  98. this.Controls.Add(this.c_ProgressPercent);
  99. this.Controls.Add(this.c_Progress);
  100. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
  101. this.Name = "EraseProgressForm";
  102. this.ShowInTaskbar = false;
  103. this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
  104. this.Text = "擦除进展";
  105. this.ResumeLayout(false);
  106. }
  107. #endregion
  108. protected override void OnLoad(EventArgs e)
  109. {
  110. base.OnLoad (e);
  111. c_Caption.Text = "正在擦除 " + m_drive.DeviceName;
  112. // Get the erasing time for the erasing method chosen.
  113. // We will use this time as an estimate of the process
  114. // duration.
  115. //获取擦除时间选择擦除方法。
  116. //我们将使用这个时间作为处理的估计
  117. //持续时间。
  118. //
  119. m_iErasingTime = m_drive.get_CDRWErasingTime (m_bQuick);
  120. // We will now start a timer that will be used for updating
  121. // the elapsed time.
  122. //我们现在开始,将用于更新的计时器
  123. //所用的时间。
  124. //
  125. m_timeStart = System.DateTime.Now;
  126. m_timer = new System.Timers.Timer (500);
  127. m_timer.Elapsed += new System.Timers.ElapsedEventHandler(m_timer_Elapsed);
  128. m_timer.Start ();
  129. // Subscribe to the OnDoneErase event.
  130. //订阅OnDoneErase事件。
  131. //
  132. m_evOnDoneErase = new _INeroDriveEvents_OnDoneEraseEventHandler(m_drive_OnDoneErase);
  133. m_drive.OnDoneErase += m_evOnDoneErase;
  134. // Finally, start the erase process.
  135. //最后,启动擦除过程。
  136. //
  137. m_drive.EraseDisc (m_bQuick, NERO_ERASE_MODE.NERO_ERASE_MODE_DEFAULT);
  138. }
  139. protected override void OnClosed(EventArgs e)
  140. {
  141. base.OnClosed (e);
  142. // When the form is closed, make sure to unsubscribe from
  143. // the event.
  144. //
  145. m_drive.OnDoneErase -= m_evOnDoneErase;
  146. }
  147. private void m_drive_OnDoneErase(ref bool Ok)
  148. {
  149. // When the erase process is done, let's stop
  150. // the timer.
  151. //
  152. m_timer.Stop ();
  153. // If we are required to show the result dialog,
  154. // this is the time and place to do it.
  155. //
  156. if (m_bShowResultDialog)
  157. {
  158. // First hide the progress form, then show the success
  159. // or failure.
  160. //
  161. this.Hide ();
  162. MessageBox.Show (this, "Erase operation was " + (Ok? "successful!": "unsuccessful!"));
  163. }
  164. // Auto close the dialog when the erase is finished.
  165. //
  166. this.Close ();
  167. }
  168. private void m_timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  169. {
  170. // This method is called when the timer period elapses.
  171. // We should update the elapsed time here.
  172. //
  173. TimeSpan ts = System.DateTime.Now - m_timeStart;
  174. int iElapsedTime = ts.Minutes*60 + ts.Seconds;
  175. int iPercent = (iElapsedTime*100)/m_iErasingTime;
  176. c_ProgressPercent.Text = iPercent.ToString () + "%";
  177. c_Progress.Value = iPercent;
  178. }
  179. }
  180. }