WPF中彈出文件夾瀏覽對話框


附一個共享目錄正則表達式判斷:

bool result= System.Text.RegularExpressions.Regex.IsMatch("\\pc-test\share", @"^\\\\[a-zA-Z0-9\.-]+(\\([^\\\?\/\*\|<>:" + "\"" + "])+){1,}$");

 

        private void btnSelectNetShareDir_Click(object sender, RoutedEventArgs e)
        {
            txtNetUploadDir.Text = string.Empty;

            System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
            System.Windows.Interop.HwndSource hwn = PresentationSource.FromVisual(this) as System.Windows.Interop.HwndSource;
            System.Windows.Forms.IWin32Window win = new WinFormWindow(hwn.Handle);
            fbd.ShowNewFolderButton = true;
            fbd.Description = "請選擇共享目錄...";
            if (fbd.ShowDialog(win) == System.Windows.Forms.DialogResult.OK)
            {
                txtNetUploadDir.Text = fbd.SelectedPath;
            }
        }
        public class WinFormWindow : System.Windows.Forms.IWin32Window
        {
            IntPtr _handle;
            public WinFormWindow(IntPtr handle)
            {
                _handle = handle;
            }
            IntPtr System.Windows.Forms.IWin32Window.Handle
            {
                get { return _handle; }
            }
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM