NodesCollectionEditor.cs 928 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Collections;
  7. using System.ComponentModel;
  8. using System.ComponentModel.Design;
  9. using System.Windows.Forms.Design;
  10. // 自定义编辑器,用于 ReadNodes 属性
  11. public class NodesCollectionEditor : CollectionEditor
  12. {
  13. public NodesCollectionEditor(Type type) : base(type)
  14. {
  15. }
  16. // 禁用添加新项
  17. protected override object CreateInstance(Type itemType)
  18. {
  19. // 返回 null 表示不允许创建新实例
  20. //return null;
  21. // 或者抛出异常(效果类似,但返回 null 更“安静”)
  22. throw new NotSupportedException("不允许在此处添加新节点。请使用 'NodeToAdd' 属性添加。");
  23. }
  24. protected override bool CanRemoveInstance(object value)
  25. {
  26. return true; // 返回 false 表示不允许删除
  27. }
  28. }