From 578c868dc9f04b92dafcaf12f6da7ee9ce2498c0 Mon Sep 17 00:00:00 2001 From: dong <1278815766@qq.com> Date: Mon, 23 Jun 2025 14:59:11 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E6=8B=A9=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E6=97=B6=E5=8F=AF=E4=BB=A5=E5=86=8D=E5=AF=BC=E8=88=AA=E6=9D=A5?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Form1.cs | 22 ++++++++++++++++------ MD5Create.csproj | 6 ++++++ packages.config | 2 ++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Form1.cs b/Form1.cs index 5eb80d1..99fb155 100644 --- a/Form1.cs +++ b/Form1.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using System.Windows.Forms; using System.Xml; using Newtonsoft.Json; +using Microsoft.WindowsAPICodePack.Dialogs; namespace MD5Create { @@ -49,13 +50,22 @@ namespace MD5Create private void Choose1_Button_Click(object sender, EventArgs e) { - folderBrowserDialog1.Description = "请选择文件夹"; - folderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer; - folderBrowserDialog1.ShowNewFolderButton = true; - if (Path1_Box.Text.Length > 0) folderBrowserDialog1.SelectedPath = Path1_Box.Text; - if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) + // 使用 Windows API Code Pack 中的 CommonOpenFileDialog,开启文件夹选择模式 + using (var dialog = new CommonOpenFileDialog()) { - Path1_Box.Text = folderBrowserDialog1.SelectedPath; + dialog.Title = "请选择文件夹"; + dialog.IsFolderPicker = true; // 文件夹选择模式 + dialog.AllowNonFileSystemItems = false; + + if (!string.IsNullOrWhiteSpace(Path1_Box.Text) && Directory.Exists(Path1_Box.Text)) + { + dialog.InitialDirectory = Path1_Box.Text; // 打开到当前路径 + } + + if (dialog.ShowDialog() == CommonFileDialogResult.Ok) + { + Path1_Box.Text = dialog.FileName; // 选择的文件夹路径 + } } } diff --git a/MD5Create.csproj b/MD5Create.csproj index 20ad39e..d4f4448 100644 --- a/MD5Create.csproj +++ b/MD5Create.csproj @@ -33,6 +33,12 @@ 4 + + packages\WindowsAPICodePack-Core.1.1.2\lib\Microsoft.WindowsAPICodePack.dll + + + packages\WindowsAPICodePack-Shell.1.1.1\lib\Microsoft.WindowsAPICodePack.Shell.dll + packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/packages.config b/packages.config index fef83be..f0dc6f8 100644 --- a/packages.config +++ b/packages.config @@ -1,4 +1,6 @@  + + \ No newline at end of file