SpeedComboBox.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. // This is a reusable class derived from ComboBox meant
  10. // to display both read and write speeds.
  11. //
  12. public class SpeedComboBox : System.Windows.Forms.ComboBox
  13. {
  14. // This is a private class that represents an item
  15. // of the combobox. We use it to store both textual
  16. // repesentation as well as the actual integer value.
  17. //
  18. public class CBItem
  19. {
  20. public string m_sItem;
  21. public int m_iSpeed;
  22. public CBItem (string sItem, int iSpeed)
  23. {
  24. m_sItem = sItem;
  25. m_iSpeed = iSpeed;
  26. }
  27. public override string ToString()
  28. {
  29. return m_sItem;
  30. }
  31. }
  32. // This is a flag that tells whether the "Maximum" speed
  33. // should be displayed or not.
  34. //
  35. public bool m_bUseMaximum;
  36. // The contructor.
  37. //
  38. public SpeedComboBox ()
  39. {
  40. m_bUseMaximum = true;
  41. }
  42. // Return textual representation of the currently selected
  43. // speed. If nothing is selected, return "Maximum" or "<none>"
  44. // depending on requirements.
  45. //
  46. public new string ToString ()
  47. {
  48. return this.SelectedItem == null? (m_bUseMaximum? "Maximum": "<none>"): this.SelectedItem.ToString ();
  49. }
  50. // Get the current speed.
  51. //
  52. public int GetSpeed ()
  53. {
  54. return this.SelectedItem == null? 0: ((CBItem) this.SelectedItem).m_iSpeed;
  55. }
  56. // Populate the combobox from the NeroSpeeds.
  57. //
  58. public void Populate (NeroSpeeds speeds)
  59. {
  60. // First clear everything.
  61. //
  62. this.Items.Clear ();
  63. // If we should add "Maximum", do it here and now.
  64. //
  65. if (m_bUseMaximum)
  66. {
  67. this.Items.Add (new CBItem ("Maximum", 0));
  68. }
  69. else
  70. {
  71. // If we should not add "Maximum", see if there is at
  72. // least one speed. If not, add "<none>".
  73. //
  74. if (speeds.Count == 0)
  75. {
  76. this.Items.Add (new CBItem ("<none>", 0));
  77. }
  78. }
  79. // Now, add each speed from the NeroSpeeds collection.
  80. //
  81. foreach (int iSpeed in speeds)
  82. {
  83. float fSpeed = iSpeed/(float) speeds.BaseSpeedKBs;
  84. this.Items.Add (new CBItem (fSpeed.ToString () + "x (" + iSpeed.ToString () + " kb/s)", iSpeed));
  85. }
  86. // Select the first speed as default.
  87. //
  88. this.SelectedIndex = 0;
  89. }
  90. }
  91. }