internal static void UpdateFieldsCheckedListBoxColumnWidth(CheckedListBox checkedListBox)
 {
     int num = 0;
     using (Graphics graphics = checkedListBox.CreateGraphics())
     {
         foreach (object obj2 in checkedListBox.Items)
         {
             string text = obj2.ToString();
             num = Math.Max(num, (int) graphics.MeasureString(text, checkedListBox.Font).Width);
         }
     }
     num += 50;
     checkedListBox.ColumnWidth = num;
 }
        /// <summary>
        /// Edits the specified object's value using the editor style indicated by the
        /// System.Drawing.Design.UITypeEditor.GetEditStyle() method</summary>
        /// <param name="context">An System.ComponentModel.ITypeDescriptorContext that can be used to gain
        /// additional context information</param>
        /// <param name="provider">An System.IServiceProvider that this editor can use to obtain services</param>
        /// <param name="value">The object to edit</param>
        /// <returns>The new value of the object. If the value of the object has not changed, this should
        /// return the same object it was passed.</returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            m_editorService =
                provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

            if (m_editorService != null)
            {
                CheckedListBox checkedListBox = new CheckedListBox();
                checkedListBox.CheckOnClick = true;
                foreach (string displayName in m_displayNames)
                    checkedListBox.Items.Add(displayName);

                // size control so all strings are completely visible
                using (System.Drawing.Graphics g = checkedListBox.CreateGraphics())
                {
                    float width = 0f;

                    foreach (string displayName in m_displayNames)
                    {
                        float w = g.MeasureString(displayName, checkedListBox.Font).Width;
                        width = Math.Max(width, w);
                    }

                    float height = m_displayNames.Length * checkedListBox.ItemHeight;
                    int scrollBarThickness = SystemInformation.VerticalScrollBarWidth;
                    if (height > checkedListBox.Height - 4) // vertical scrollbar?
                        width += SystemInformation.VerticalScrollBarWidth;

                    if (width > checkedListBox.Width)
                        checkedListBox.Width = (int)width + 31; // magic number from Windows.Forms dll
                }

                if (value is string)
                    FillCheckedListBoxFromString(value, checkedListBox);
                else if (value is int)
                    FillCheckedListBoxFromInt(value, checkedListBox);
                // otherwise, ignore value

                m_editorService.DropDownControl(checkedListBox);

                object newValue;
                if (value is string)
                    newValue = ExtractStringFromCheckedListBox(checkedListBox);
                else
                    newValue = ExtractIntFromCheckedListBox(checkedListBox);
                // be careful to return the same object if the value didn't change
                if (!newValue.Equals(value))
                    value = newValue;
            }

            return value;
        }