123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using NEROLib;
- namespace LYFZ.NeroDiscBurn.NET
- {
- // This is a reusable class derived from ComboBox meant
- // to display both read and write speeds.
- //
- public class SpeedComboBox : System.Windows.Forms.ComboBox
- {
- // This is a private class that represents an item
- // of the combobox. We use it to store both textual
- // repesentation as well as the actual integer value.
- //
- public class CBItem
- {
- public string m_sItem;
- public int m_iSpeed;
- public CBItem (string sItem, int iSpeed)
- {
- m_sItem = sItem;
- m_iSpeed = iSpeed;
- }
- public override string ToString()
- {
- return m_sItem;
- }
- }
- // This is a flag that tells whether the "Maximum" speed
- // should be displayed or not.
- //
- public bool m_bUseMaximum;
- // The contructor.
- //
- public SpeedComboBox ()
- {
- m_bUseMaximum = true;
- }
- // Return textual representation of the currently selected
- // speed. If nothing is selected, return "Maximum" or "<none>"
- // depending on requirements.
- //
- public new string ToString ()
- {
- return this.SelectedItem == null? (m_bUseMaximum? "Maximum": "<none>"): this.SelectedItem.ToString ();
- }
- // Get the current speed.
- //
- public int GetSpeed ()
- {
- return this.SelectedItem == null? 0: ((CBItem) this.SelectedItem).m_iSpeed;
- }
- // Populate the combobox from the NeroSpeeds.
- //
- public void Populate (NeroSpeeds speeds)
- {
- // First clear everything.
- //
- this.Items.Clear ();
- // If we should add "Maximum", do it here and now.
- //
- if (m_bUseMaximum)
- {
- this.Items.Add (new CBItem ("Maximum", 0));
- }
- else
- {
- // If we should not add "Maximum", see if there is at
- // least one speed. If not, add "<none>".
- //
- if (speeds.Count == 0)
- {
- this.Items.Add (new CBItem ("<none>", 0));
- }
- }
- // Now, add each speed from the NeroSpeeds collection.
- //
- foreach (int iSpeed in speeds)
- {
- float fSpeed = iSpeed/(float) speeds.BaseSpeedKBs;
- this.Items.Add (new CBItem (fSpeed.ToString () + "x (" + iSpeed.ToString () + " kb/s)", iSpeed));
- }
- // Select the first speed as default.
- //
- this.SelectedIndex = 0;
- }
- }
- }
|