选择文件夹时可以再导航来输入路径
This commit is contained in:
22
Form1.cs
22
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; // 选择的文件夹路径
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -33,6 +33,12 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.WindowsAPICodePack, Version=1.1.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>packages\WindowsAPICodePack-Core.1.1.2\lib\Microsoft.WindowsAPICodePack.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.WindowsAPICodePack.Shell, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>packages\WindowsAPICodePack-Shell.1.1.1\lib\Microsoft.WindowsAPICodePack.Shell.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net472" />
|
||||
<package id="WindowsAPICodePack-Core" version="1.1.2" targetFramework="net472" />
|
||||
<package id="WindowsAPICodePack-Shell" version="1.1.1" targetFramework="net472" />
|
||||
</packages>
|
Reference in New Issue
Block a user