C# 如何定义让PropertyGrid控件显示[...]按钮,并且点击后以下拉框形式显示自定义

时间:2022-04-13 04:00:09

using System.Drawing.Design; using System.Windows.Forms.Design; namespace Simon.WinForms.Examples.PropertyGrid { public class Editor : UITypeEditor { public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context) { // 编辑属性值时,在右侧显示...更多按钮 return UITypeEditorEditStyle.Modal; } public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value) { var edSvc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService; if (edSvc != null) { var popedControl = new EditorControl(); // 还有ShowDialog这种方式,,可以弹出一个窗体来进行编辑 edSvc.DropDownControl(popedControl); value = popedControl.result; } return base.EditValue(context, provider, value); } } }