using System; using System.ComponentModel; using System.Drawing.Design; using System.Windows.Forms.Design; namespace GeoSigma.SigmaDrawerStyle { /// /// 岩性编辑器 /// public class PropertyEditorListBox : UITypeEditor { /// public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context) { return UITypeEditorEditStyle.DropDown; } /// public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc == null) { return value; } if (!(value is string) && value != null) { return value; } var attr = context?.PropertyDescriptor?.Attributes[typeof(ListBoxEditorAttribute)] as ListBoxEditorAttribute; if (attr == null) { return value; } var listBox = ListBoxEditorFactory.Create(attr.ControlKey); if (listBox == null) { return value; } listBox.SelectedIndexChanged += (s, e) => { edSvc.CloseDropDown(); }; edSvc.DropDownControl(listBox); return listBox.SelectedItem?.ToString() ?? value; } } }