NodeTypeEditor.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing.Design;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms.Design;
  9. using System.Windows.Forms;
  10. using XmlToTreeView;
  11. public class NodeTypeEditor: UITypeEditor
  12. {
  13. public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
  14. {
  15. return UITypeEditorEditStyle.Modal;
  16. }
  17. public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
  18. {
  19. if (provider != null)
  20. {
  21. // 获取对话框服务
  22. IWindowsFormsEditorService editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
  23. if (editorService != null)
  24. {
  25. // 创建自定义选择窗口
  26. NodeSelectionDialog dialog = new NodeSelectionDialog();
  27. // 设置初始值
  28. dialog.SelectedValue = (Node)value;
  29. // 显示模态对话框
  30. if (editorService.ShowDialog(dialog) == DialogResult.OK)
  31. {
  32. // 返回用户选择的值
  33. return dialog.SelectedValue;
  34. }
  35. }
  36. }
  37. return value;
  38. }
  39. }