/// <summary> /// Calculates the width of the drop down list of the given combo box /// </summary> /// <param name="combo">Combo box to base calculate from</param> /// <returns>Width of longest string in combo box items</returns> /// <history> /// [Curtis_Beard] 11/21/2005 Created /// </history> public static int CalculateDropDownWidth(BNComboBox combo) { const int EXTRA = 10; int _max = combo.Width; using (Graphics g = combo.CreateGraphics()) { string _itemValue = string.Empty; SizeF _size; foreach (object _item in combo.Items) { _itemValue = _item.ToString(); _size = g.MeasureString(_itemValue, combo.Font); if (_size.Width > _max) { _max = Convert.ToInt32(_size.Width); } } // keep original width if no item longer if (_max != combo.Width) { _max += EXTRA; } } return(_max); }
/// <summary> /// Retrieves all the ComboBox entries as a string. /// </summary> /// <param name="combo">ComboBox</param> /// <returns>string of entries</returns> /// <history> /// [Curtis_Beard] 11/03/2006 Created /// </history> public static string GetComboBoxEntriesAsString(BNComboBox combo) { string[] entries = new string[combo.Items.Count]; for (int i = 0; i < combo.Items.Count; i++) { entries[i] = combo.Items[i].ToString(); } return(string.Join(Constants.SEARCH_ENTRIES_SEPARATOR, entries)); }
void onResize(object sender, EventArgs e) { BNComboBox c = this.Parent as BNComboBox; c.AdjustControls(); }