public static FolderBrowserDialogEx ComputerBrowser() { FolderBrowserDialogEx x = new FolderBrowserDialogEx(); // avoid MBRO comppiler warning when passing _rootFolderLocation as a ref: x.BecomeComputerBrowser(); return(x); }
/// <summary> /// Calling this method is identical to calling the ShowDialog method of the provided /// FolderBrowserDialog, except that an attempt will be made to scroll the Tree View /// to make the currently selected folder visible in the dialog window. /// </summary> /// <param name="dlg"></param> /// <param name="parent"></param> /// <returns></returns> public static DialogResult ShowFolderBrowser(FolderBrowserDialogEx dlg, IWin32Window parent = null) { DialogResult result = DialogResult.Cancel; int retries = 10; using (Timer t = new Timer()) { t.Tick += (s, a) => { if (retries > 0) { --retries; IntPtr hwndDlg = FindWindow((string)null, _topLevelSearchString); if (hwndDlg != IntPtr.Zero) { IntPtr hwndFolderCtrl = GetDlgItem(hwndDlg, _dlgItemBrowseControl); if (hwndFolderCtrl != IntPtr.Zero) { IntPtr hwndTV = GetDlgItem(hwndFolderCtrl, _dlgItemTreeView); if (hwndTV != IntPtr.Zero) { IntPtr item = SendMessage(hwndTV, (uint)TVM_GETNEXTITEM, new IntPtr(TVGN_CARET), IntPtr.Zero); if (item != IntPtr.Zero) { SendMessage(hwndTV, TVM_ENSUREVISIBLE, IntPtr.Zero, item); retries = 0; t.Stop(); } } } } } else { // // We failed to find the Tree View control. // // As a fall back (and this is an UberUgly hack), we will send // some fake keystrokes to the application in an attempt to force // the Tree View to scroll to the selected item. // t.Stop(); SendKeys.Send("{TAB}{TAB}{DOWN}{DOWN}{UP}{UP}"); } }; t.Interval = 10; t.Start(); result = dlg.ShowDialog(parent); } return(result); }
DialogResult showDefaultDialogEx(IWin32Window owner) { using (var fbd = new FolderBrowserDialogEx()) { fbd.Reset(); fbd.Description = this.Title; fbd.SelectedPath = this.DirectoryPath; fbd.ShowEditBox = true; fbd.NewStyle = true; fbd.ShowNewFolderButton = true; fbd.DontIncludeNetworkFoldersBelowDomainLevel = true; fbd.ShowFullPathInEditBox = false; var result = FolderBrowserLauncher.ShowFolderBrowser(fbd, owner); //var result = fbd.ShowDialog(owner); DirectoryPath = fbd.SelectedPath; return(result); } }