From ba9b8edcdc9d2dd3fccdd102e986cfd5f3043ac3 Mon Sep 17 00:00:00 2001 From: ww-rm Date: Mon, 24 Mar 2025 18:49:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E7=BC=96=E8=BE=91=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpineViewer/UITypeEditor.cs | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 SpineViewer/UITypeEditor.cs diff --git a/SpineViewer/UITypeEditor.cs b/SpineViewer/UITypeEditor.cs new file mode 100644 index 0000000..8d0700e --- /dev/null +++ b/SpineViewer/UITypeEditor.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing.Design; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms.Design; + +namespace SpineViewer +{ + /// + /// 使用 FolderBrowserDialog 的文件夹路径编辑器 + /// + public class FolderNameEditor : UITypeEditor + { + public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext? context) + { + // 指定编辑风格为 Modal 对话框, 提供右边用来点击的按钮 + return UITypeEditorEditStyle.Modal; + } + + public override object? EditValue(ITypeDescriptorContext? context, IServiceProvider provider, object? value) + { + // 重写 EditValue 方法,提供自定义的文件夹选择对话框逻辑 + using var dialog = new FolderBrowserDialog(); + + // 如果当前值为有效路径,则设置为初始选中路径 + if (value is string currentPath && Directory.Exists(currentPath)) + dialog.SelectedPath = currentPath; + + if (dialog.ShowDialog() == DialogResult.OK) + value = dialog.SelectedPath; + + return value; + } + } +}