26°

WPF 目录、文件弹出框

1.System.Windows.Forms

目录选择

     FolderBrowserDialog dialog = new FolderBrowserDialog();
        </span><span style="color: #0000ff;">if</span> (dialog.ShowDialog() ==<span style="color: #000000;"> System.Windows.Forms.DialogResult.OK)
        {
            </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">string</span><span style="color: #000000;">.IsNullOrEmpty(dialog.SelectedPath))
            {
               System.Windows.MessageBox.Show(<span data-mce-="">"<span data-mce-="">Click OK<span data-mce-="">"<span data-mce-="">);</span></span></span></span></span><span style="color: #000000;">
              
            }
        }</span></pre> 

文件选择

     OpenFileDialog openFileDialog= new OpenFileDialog();
            if (openFileDialog.ShowDialog()== System.Windows.Forms.DialogResult.OK)
            {
               System.Windows.MessageBox.Show("Click OK");
            }

  

 

2.CommonOpenFileDialog

添加WindowsAPICodePack-Shell 的Nuget引用

            CommonOpenFileDialog dialog = new CommonOpenFileDialog();
            dialog.Title = "";
            dialog.AddToMostRecentlyUsedList = false;
            dialog.AllowNonFileSystemItems = false;
            dialog.EnsurePathExists = true;
            dialog.ShowPlacesList = true;
            dialog.IsFolderPicker = true;//True选择文件目录,false选择文件夹
            if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
              System.Windows.MessageBox.Show(</span><span style="color: #800000;">"</span><span style="color: #800000;">Click OK</span><span style="color: #800000;">"</span><span style="color: #000000;">);
        }                </span></pre> 

 

本文转载自博客园,原文链接:https://www.cnblogs.com/qlbky/p/11977537.html

全部评论: 0

    我有话说: