You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kev/Drawer/UCDraw/SigmaDrawerWellStyle/PropertyEditorListBox.cs

56 lines
1.6 KiB
C#

using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms.Design;
namespace GeoSigma.SigmaDrawerStyle
{
/// <summary>
/// 岩性编辑器
/// </summary>
public class PropertyEditorListBox : UITypeEditor
{
/// <inheritdoc/>
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
/// <inheritdoc/>
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;
}
}
}