ChooseSpeed.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 ChooseSpeedForm.
  11. /// </summary>
  12. public class ChooseSpeedForm : System.Windows.Forms.Form
  13. {
  14. public NeroDrive m_drive;
  15. private bool m_bWriteSpeeds;
  16. private _INeroDriveEvents_OnDoneCDInfoEventHandler m_evOnDoneCDInfo;
  17. private ControlEnabler m_controlEnabler;
  18. private System.Windows.Forms.Button c_OK;
  19. private System.Windows.Forms.Button c_Cancel;
  20. private System.Windows.Forms.Label label1;
  21. private SpeedComboBox c_Speeds;
  22. /// <summary>
  23. /// Required designer variable.
  24. /// </summary>
  25. private System.ComponentModel.Container components = null;
  26. public ChooseSpeedForm(NeroDrive drive, bool bWriteSpeeds)
  27. {
  28. //
  29. // Required for Windows Form Designer support
  30. //
  31. InitializeComponent();
  32. m_drive = drive;
  33. m_bWriteSpeeds = bWriteSpeeds;
  34. m_controlEnabler = new ControlEnabler (this);
  35. }
  36. /// <summary>
  37. /// Clean up any resources being used.
  38. /// </summary>
  39. protected override void Dispose( bool disposing )
  40. {
  41. if( disposing )
  42. {
  43. if(components != null)
  44. {
  45. components.Dispose();
  46. }
  47. }
  48. base.Dispose( disposing );
  49. }
  50. #region Windows Form Designer generated code
  51. /// <summary>
  52. /// Required method for Designer support - do not modify
  53. /// the contents of this method with the code editor.
  54. /// </summary>
  55. private void InitializeComponent()
  56. {
  57. this.c_OK = new System.Windows.Forms.Button();
  58. this.c_Cancel = new System.Windows.Forms.Button();
  59. this.c_Speeds = new SpeedComboBox();
  60. this.label1 = new System.Windows.Forms.Label();
  61. this.SuspendLayout();
  62. //
  63. // c_OK
  64. //
  65. this.c_OK.DialogResult = System.Windows.Forms.DialogResult.OK;
  66. this.c_OK.Location = new System.Drawing.Point(144, 8);
  67. this.c_OK.Name = "c_OK";
  68. this.c_OK.TabIndex = 2;
  69. this.c_OK.Text = "OK";
  70. //
  71. // c_Cancel
  72. //
  73. this.c_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  74. this.c_Cancel.Location = new System.Drawing.Point(144, 40);
  75. this.c_Cancel.Name = "c_Cancel";
  76. this.c_Cancel.TabIndex = 3;
  77. this.c_Cancel.Text = "Cancel";
  78. //
  79. // c_Speeds
  80. //
  81. this.c_Speeds.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  82. this.c_Speeds.Location = new System.Drawing.Point(8, 24);
  83. this.c_Speeds.Name = "c_Speeds";
  84. this.c_Speeds.Size = new System.Drawing.Size(121, 21);
  85. this.c_Speeds.TabIndex = 1;
  86. //
  87. // label1
  88. //
  89. this.label1.Location = new System.Drawing.Point(8, 8);
  90. this.label1.Name = "label1";
  91. this.label1.Size = new System.Drawing.Size(100, 16);
  92. this.label1.TabIndex = 0;
  93. this.label1.Text = "Speeds:";
  94. //
  95. // ChooseSpeedForm
  96. //
  97. this.AcceptButton = this.c_OK;
  98. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  99. this.CancelButton = this.c_Cancel;
  100. this.ClientSize = new System.Drawing.Size(226, 72);
  101. this.Controls.Add(this.label1);
  102. this.Controls.Add(this.c_Speeds);
  103. this.Controls.Add(this.c_OK);
  104. this.Controls.Add(this.c_Cancel);
  105. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  106. this.MaximizeBox = false;
  107. this.MinimizeBox = false;
  108. this.Name = "ChooseSpeedForm";
  109. this.ShowInTaskbar = false;
  110. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  111. this.Text = "Choose Speed";
  112. this.ResumeLayout(false);
  113. }
  114. #endregion
  115. protected override void OnLoad(EventArgs e)
  116. {
  117. base.OnLoad (e);
  118. // The same form is used both for read and write speeds.
  119. //
  120. this.Text = m_bWriteSpeeds? "Choose write speed:": "Choose read speed:";
  121. // Disable all form controls and display wait cursor.
  122. //
  123. c_Speeds.Items.Clear ();
  124. m_controlEnabler.EnableAllControls (false);
  125. this.Cursor = Cursors.WaitCursor;
  126. // Subscribe to event and do a disc info.
  127. //
  128. m_evOnDoneCDInfo = new _INeroDriveEvents_OnDoneCDInfoEventHandler(m_drive_OnDoneCDInfo);
  129. m_drive.OnDoneCDInfo += m_evOnDoneCDInfo;
  130. m_drive.CDInfo (0);
  131. }
  132. public new string ToString ()
  133. {
  134. return c_Speeds.ToString ();
  135. }
  136. public int GetSpeed ()
  137. {
  138. return c_Speeds.GetSpeed ();
  139. }
  140. private void m_drive_OnDoneCDInfo(INeroCDInfo pCDInfo)
  141. {
  142. // Unsubscribe from event, get the speeds and populate the
  143. // speeds combobox with it.
  144. //
  145. m_drive.OnDoneCDInfo -= m_evOnDoneCDInfo;
  146. NERO_MEDIA_TYPE nmt = pCDInfo != null? pCDInfo.MediaType: NERO_MEDIA_TYPE.NERO_MEDIA_NONE;
  147. NeroSpeeds speeds = m_drive.get_AvailableSpeeds (m_bWriteSpeeds? NERO_ACCESSTYPE.NERO_ACCESSTYPE_WRITE: NERO_ACCESSTYPE.NERO_ACCESSTYPE_READ, nmt);
  148. c_Speeds.Populate (speeds);
  149. this.Cursor = Cursors.Default;
  150. m_controlEnabler.EnableAllControls (true);
  151. }
  152. }
  153. }