using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using NEROLib; namespace NeroFiddlesCOM.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. // private 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 "" // depending on requirements. // public new string ToString () { return this.SelectedItem == null? (m_bUseMaximum? "Maximum": ""): 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 "". // if (speeds.Count == 0) { this.Items.Add (new CBItem ("", 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; } } }