Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否有PropertyGrid集合编辑器;加上「;按钮事件还是覆盖?_C#_Winforms_Propertygrid_Collectioneditor_Custom Collection - Fatal编程技术网

C# 是否有PropertyGrid集合编辑器;加上「;按钮事件还是覆盖?

C# 是否有PropertyGrid集合编辑器;加上「;按钮事件还是覆盖?,c#,winforms,propertygrid,collectioneditor,custom-collection,C#,Winforms,Propertygrid,Collectioneditor,Custom Collection,单击Windows窗体PropertyGrid集合编辑器“添加”按钮时是否会触发事件或函数?(见图) 我想添加一些自定义代码,以便在按下此按钮时运行 我将自定义集合用于对象列表(CollectionBase)。当按下Add按钮时,我的构造函数被调用,但在调用列表中我看不到其他可以插入一些自定义代码的函数 没有文档化的方法,您必须使用自己的编辑器。但是您可以从标准编辑器类派生。以下是此类黑客的一个例子: 在集合属性上定义自定义编辑器属性,如下所示: [Editor(typeof(MyCollect

单击Windows窗体PropertyGrid集合编辑器“添加”按钮时是否会触发事件或函数?(见图)

我想添加一些自定义代码,以便在按下此按钮时运行

我将自定义集合用于对象列表(CollectionBase)。当按下Add按钮时,我的构造函数被调用,但在调用列表中我看不到其他可以插入一些自定义代码的函数


没有文档化的方法,您必须使用自己的编辑器。但是您可以从标准编辑器类派生。以下是此类黑客的一个例子:

在集合属性上定义自定义编辑器属性,如下所示:

[Editor(typeof(MyCollectionEditor), typeof(UITypeEditor))]
public List<Child> Children { get; }

“添加”按钮是一个简单的Winforms按钮,因此您可以使用它执行任何操作。

可能。首先,重新审视您的
CollectionBase
决策:。我使用自定义UITypeEditor处理过复杂集合。它将在正在创建的类型上查找接口,并调用该类来执行任何操作。我不完全确定道具网格是否会使用UITypeEditor,但很容易找到。
// CollectionEditor needs a reference to System.Design.dll
public class MyCollectionEditor : CollectionEditor
{
    public MyCollectionEditor(Type type)
        : base(type)
    {
    }

    protected override CollectionForm CreateCollectionForm()
    {
        CollectionForm form = base.CreateCollectionForm();
        var addButton = (ButtonBase)form.Controls.Find("addButton", true).First();
        addButton.Click += (sender, e) =>
            {
                MessageBox.Show("hello world");
            };
        return form;
    }
}