| 12345678910111213141516171819202122232425262728293031 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Collections;
- using System.ComponentModel;
- using System.ComponentModel.Design;
- using System.Windows.Forms.Design;
- // 自定义编辑器,用于 ReadNodes 属性
- public class NodesCollectionEditor : CollectionEditor
- {
- public NodesCollectionEditor(Type type) : base(type)
- {
- }
- // 禁用添加新项
- protected override object CreateInstance(Type itemType)
- {
- // 返回 null 表示不允许创建新实例
- //return null;
- // 或者抛出异常(效果类似,但返回 null 更“安静”)
- throw new NotSupportedException("不允许在此处添加新节点。请使用 'NodeToAdd' 属性添加。");
- }
- protected override bool CanRemoveInstance(object value)
- {
- return true; // 返回 false 表示不允许删除
- }
- }
|