first commit
This commit is contained in:
33
DCIT.App/Presentation/ModernFolderPicker.cs
Normal file
33
DCIT.App/Presentation/ModernFolderPicker.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DCIT.App.Presentation
|
||||
{
|
||||
internal static class ModernFolderPicker
|
||||
{
|
||||
public static bool TrySelectFolder(IWin32Window owner, string initialDirectory, out string selectedPath)
|
||||
{
|
||||
selectedPath = null;
|
||||
using (var dialog = new OpenFileDialog())
|
||||
{
|
||||
dialog.ValidateNames = false;
|
||||
dialog.CheckFileExists = false;
|
||||
dialog.CheckPathExists = true;
|
||||
dialog.FileName = "选择当前文件夹";
|
||||
dialog.Filter = "文件夹|*.folder";
|
||||
if (!string.IsNullOrWhiteSpace(initialDirectory) && Directory.Exists(initialDirectory))
|
||||
{
|
||||
dialog.InitialDirectory = initialDirectory;
|
||||
}
|
||||
|
||||
if (dialog.ShowDialog(owner) != DialogResult.OK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
selectedPath = Path.GetDirectoryName(dialog.FileName);
|
||||
return !string.IsNullOrWhiteSpace(selectedPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user