/// <summary> /// Shows the dialog /// </summary> /// <param name="hWndOwner">Handle of the control to be parent</param> /// <returns>True if the user presses OK else false</returns> public bool ShowDialog(IntPtr hWndOwner) { bool flag = false; if (Environment.OSVersion.Version.Major >= 6) { var r = new Reflector("System.Windows.Forms"); uint num = 0; Type typeIFileDialog = r.GetType("FileDialogNative.IFileDialog"); object dialog = r.Call(ofd, "CreateVistaDialog"); r.Call(ofd, "OnBeforeVistaDialog", dialog); uint options = (uint)r.CallAs(typeof(System.Windows.Forms.FileDialog), ofd, "GetOptions"); options |= (uint)r.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS"); r.CallAs(typeIFileDialog, dialog, "SetOptions", options); object pfde = r.New("FileDialog.VistaDialogEvents", ofd); object[] parameters = new object[] { pfde, num }; r.CallAs2(typeIFileDialog, dialog, "Advise", parameters); num = (uint)parameters[1]; try { int num2 = (int)r.CallAs(typeIFileDialog, dialog, "Show", hWndOwner); flag = 0 == num2; } finally { r.CallAs(typeIFileDialog, dialog, "Unadvise", num); GC.KeepAlive(pfde); } } else { using (var fbd = new FolderBrowserDialog()) { fbd.Description = this.Title; fbd.SelectedPath = this.InitialDirectory; fbd.ShowNewFolderButton = false; if (fbd.ShowDialog(new WindowWrapper(hWndOwner)) != DialogResult.OK) { return(false); } ofd.FileName = fbd.SelectedPath; flag = true; } } return(flag); }
/// <summary> /// Shows the dialog /// </summary> /// <returns>True if the user presses OK else false</returns> public DialogResult ShowDialog(IntPtr hWndOwner) { bool flag; if (Environment.OSVersion.Version.Major >= 6) // if current OS is windows and version Vista or higher - then use extended dialogs { var r = new Reflector("System.Windows.Forms"); uint num = 0; var typeIFileDialog = r.GetType("FileDialogNative.IFileDialog"); var dialog = r.Call(ofd, "CreateVistaDialog"); r.Call(ofd, "OnBeforeVistaDialog", dialog); var options = (uint)r.CallAs(typeof(FileDialog), ofd, "GetOptions"); options |= (uint)r.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS"); r.CallAs(typeIFileDialog, dialog, "SetOptions", options); var pfde = r.New("FileDialog.VistaDialogEvents", ofd); var parameters = new[] { pfde, num }; r.CallAs2(typeIFileDialog, dialog, "Advise", parameters); num = (uint)parameters[1]; try { var num2 = (int)r.CallAs(typeIFileDialog, dialog, "Show", hWndOwner); flag = 0 == num2; } finally { r.CallAs(typeIFileDialog, dialog, "Unadvise", num); GC.KeepAlive(pfde); } } else // in another case - use standart dialog { using (var fbd = new FolderBrowserDialog { Description = Title, SelectedPath = InitialDirectory, ShowNewFolderButton = false, RootFolder = RootFolder }) { if (fbd.ShowDialog() != DialogResult.OK) { return(DialogResult.Cancel); } ofd.FileName = fbd.SelectedPath; flag = true; } } return(flag ? DialogResult.OK : DialogResult.Cancel); }
/// <summary> /// Shows the dialog</summary> /// <param name="owner">Control to be parent</param> /// <returns>True if the user presses OK else false</returns> public DialogResult ShowDialog(IWin32Window owner) { DialogResult result; if (Environment.OSVersion.Version.Major >= 6) { var r = new Reflector("System.Windows.Forms"); uint num = 0; Type typeIFileDialog = r.GetType("FileDialogNative.IFileDialog"); object dialog = r.Call(m_ofd, "CreateVistaDialog"); r.Call(m_ofd, "OnBeforeVistaDialog", dialog); uint options = (uint)r.CallAs(typeof(FileDialog), m_ofd, "GetOptions"); options |= (uint)r.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS"); r.CallAs(typeIFileDialog, dialog, "SetOptions", options); object pfde = r.New("FileDialog.VistaDialogEvents", m_ofd); object[] parameters = new[] { pfde, num }; r.CallAs2(typeIFileDialog, dialog, "Advise", parameters); num = (uint)parameters[1]; try { int num2 = (int)r.CallAs(typeIFileDialog, dialog, "Show", owner == null ? IntPtr.Zero : owner.Handle); result = (0 == num2) ? DialogResult.OK : DialogResult.Cancel; } finally { r.CallAs(typeIFileDialog, dialog, "Unadvise", num); GC.KeepAlive(pfde); } } else { using (var fbd = new FolderBrowserDialog()) { fbd.Description = Description; fbd.SelectedPath = InitialDirectory; fbd.ShowNewFolderButton = false; result = fbd.ShowDialog(owner); if (result == DialogResult.OK) { m_ofd.FileName = fbd.SelectedPath; } } } return(result); }
private bool ShowDialog(IntPtr hWndOwner) { bool flag; if (Environment.OSVersion.Version.Major >= 6) { var r = new Reflector("System.Windows.Forms"); uint num = 0; var typeIFileDialog = r.GetType("FileDialogNative.IFileDialog"); var dialog = Reflector.Call(_ofd, "CreateVistaDialog"); Reflector.Call(_ofd, "OnBeforeVistaDialog", dialog); var options = (uint)Reflector.CallAs(typeof(FileDialog), _ofd, "GetOptions"); options |= (uint)r.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS"); Reflector.CallAs(typeIFileDialog, dialog, "SetOptions", options); var pfde = r.New("FileDialog.VistaDialogEvents", _ofd); var parameters = new[] { pfde, num }; Reflector.CallAs2(typeIFileDialog, dialog, "Advise", parameters); num = (uint)parameters[1]; try { var num2 = (int)Reflector.CallAs(typeIFileDialog, dialog, "Show", hWndOwner); flag = 0 == num2; } finally { Reflector.CallAs(typeIFileDialog, dialog, "Unadvise", num); GC.KeepAlive(pfde); } } else { var fbd = new FolderBrowserDialog { Description = Title, SelectedPath = InitialDirectory }; if (fbd.ShowDialog(new WindowWrapper(hWndOwner)) != DialogResult.OK) { return(false); } _ofd.FileName = fbd.SelectedPath; return(true); } return(flag); }
public bool ShowDialog(IntPtr hWndOwner) { bool flag = false; if (Environment.OSVersion.Version.Major >= 6) { var r = new Reflector("System.Windows.Forms"); uint num = 0; Type typeIFileDialog = r.GetType("FileDialogNative.IFileDialog"); object dialog = r.Call(ofd, "CreateVistaDialog"); r.Call(ofd, "OnBeforeVistaDialog", dialog); uint options = (uint)r.CallAs(typeof(System.Windows.Forms.FileDialog), ofd, "GetOptions"); options |= (uint)r.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS"); r.CallAs(typeIFileDialog, dialog, "SetOptions", options); object pfde = r.New("FileDialog.VistaDialogEvents", ofd); object[] parameters = new object[] { pfde, num }; r.CallAs2(typeIFileDialog, dialog, "Advise", parameters); num = (uint)parameters[1]; try { int num2 = (int)r.CallAs(typeIFileDialog, dialog, "Show", hWndOwner); flag = 0 == num2; } finally { r.CallAs(typeIFileDialog, dialog, "Unadvise", num); GC.KeepAlive(pfde); } } else { using (var fbd = new FolderBrowserDialog()) { fbd.Description = this.Title; fbd.SelectedPath = this.InitialDirectory; fbd.ShowNewFolderButton = false; if (fbd.ShowDialog(new WindowWrapper(hWndOwner)) != DialogResult.OK) return false; ofd.FileName = fbd.SelectedPath; flag = true; } } return flag; }
public bool ShowDialog(IntPtr hWndOwner) { if ((Environment.OSVersion.Version.Major >= 6) && !this.UseOldDialog) { Reflector reflector = new Reflector("System.Windows.Forms"); uint num = 0; Type type = reflector.GetType("FileDialogNative.IFileDialog"); object obj2 = reflector.Call(this.ofd, "CreateVistaDialog", new object[0]); reflector.Call(this.ofd, "OnBeforeVistaDialog", new object[] {obj2}); uint num2 = (uint) reflector.CallAs(typeof (FileDialog), this.ofd, "GetOptions", new object[0]); num2 |= (uint) reflector.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS"); reflector.CallAs(type, obj2, "SetOptions", new object[] {num2}); object obj3 = reflector.New("FileDialog.VistaDialogEvents", new object[] {this.ofd}); object[] parameters = new object[] {obj3, num}; reflector.CallAs2(type, obj2, "Advise", parameters); num = (uint) parameters[1]; try { int num3 = (int) reflector.CallAs(type, obj2, "Show", new object[] {hWndOwner}); return (0 == num3); } finally { reflector.CallAs(type, obj2, "Unadvise", new object[] {num}); GC.KeepAlive(obj3); } } FolderBrowserDialogEx ex = new FolderBrowserDialogEx(); ex.Description = this.Title; ex.SelectedPath = this.InitialDirectory; ex.ShowNewFolderButton = true; ex.ShowEditBox = true; ex.ShowFullPathInEditBox = true; if (ex.ShowDialog(new WindowWrapper(hWndOwner)) != DialogResult.OK) { return false; } this.ofd.FileName = ex.SelectedPath; return true; }
/// <summary> /// Shows the dialog /// </summary> /// <param name="hWndOwner">Handle of the control to be parent</param> /// <returns>True if the user presses OK else false</returns> public bool ShowDialog(IntPtr hWndOwner) { bool flag = false; if (PlatformHelper.GetPlatform() == Platform.OsX || PlatformHelper.GetPlatform() == Platform.Linux || Environment.OSVersion.Version.Major < 6) { flag = FallBackToFolderBrowserDialog(hWndOwner); } else { var r = new Reflector("System.Windows.Forms"); uint num = 0; Type typeIFileDialog = r.GetType("FileDialogNative.IFileDialog"); if (typeIFileDialog == null) flag = FallBackToFolderBrowserDialog(hWndOwner); else { object dialog = r.Call(ofd, "CreateVistaDialog"); r.Call(ofd, "OnBeforeVistaDialog", dialog); uint options = (uint)r.CallAs(typeof(System.Windows.Forms.FileDialog), ofd, "GetOptions"); options |= (uint)r.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS"); r.CallAs(typeIFileDialog, dialog, "SetOptions", options); object pfde = r.New("FileDialog.VistaDialogEvents", ofd); object[] parameters = new object[] { pfde, num }; r.CallAs2(typeIFileDialog, dialog, "Advise", parameters); num = (uint)parameters[1]; try { int num2 = (int)r.CallAs(typeIFileDialog, dialog, "Show", hWndOwner); flag = 0 == num2; } finally { r.CallAs(typeIFileDialog, dialog, "Unadvise", num); GC.KeepAlive(pfde); } } } return flag; }
/// <summary> /// Shows the dialog /// </summary> /// <returns>True if the user presses OK else false</returns> public DialogResult ShowDialog(IntPtr hWndOwner) { bool flag; if (Environment.OSVersion.Version.Major >= 6) // if current OS is windows and version Vista or higher - then use extended dialogs { var r = new Reflector("System.Windows.Forms"); uint num = 0; var typeIFileDialog = r.GetType("FileDialogNative.IFileDialog"); var dialog = r.Call(ofd, "CreateVistaDialog"); r.Call(ofd, "OnBeforeVistaDialog", dialog); var options = (uint)r.CallAs(typeof(FileDialog), ofd, "GetOptions"); options |= (uint)r.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS"); r.CallAs(typeIFileDialog, dialog, "SetOptions", options); var pfde = r.New("FileDialog.VistaDialogEvents", ofd); var parameters = new[] { pfde, num }; r.CallAs2(typeIFileDialog, dialog, "Advise", parameters); num = (uint)parameters[1]; try { var num2 = (int)r.CallAs(typeIFileDialog, dialog, "Show", hWndOwner); flag = 0 == num2; } finally { r.CallAs(typeIFileDialog, dialog, "Unadvise", num); GC.KeepAlive(pfde); } } else // in another case - use standart dialog { using (var fbd = new FolderBrowserDialog { Description = Title, SelectedPath = InitialDirectory, ShowNewFolderButton = false, RootFolder = RootFolder }) { if (fbd.ShowDialog() != DialogResult.OK) return DialogResult.Cancel; ofd.FileName = fbd.SelectedPath; flag = true; } } return flag ? DialogResult.OK : DialogResult.Cancel; }
/// <summary> /// Shows the dialog /// </summary> /// <param name="hWndOwner">Handle of the control to be parent</param> /// <returns>True if the user presses OK else false</returns> public bool ShowDialog(IntPtr hWndOwner) { bool flag; // TODO: Find way to use Microsoft.Win32 Reflector r = new Reflector("System.Windows.Forms"); uint num = 0; Type typeIFileDialog = r.GetType("FileDialogNative.IFileDialog"); object dialog = r.Call(ofd, "CreateVistaDialog"); r.Call(ofd, "OnBeforeVistaDialog", dialog); uint options = (uint)r.CallAs(typeof(FileDialog), ofd, "GetOptions"); options |= (uint)r.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS"); r.CallAs(typeIFileDialog, dialog, "SetOptions", options); object pfde = r.New("FileDialog.VistaDialogEvents", ofd); object[] parameters = new object[] { pfde, num }; r.CallAs2(typeIFileDialog, dialog, "Advise", parameters); num = (uint)parameters[1]; try { int num2 = (int)r.CallAs(typeIFileDialog, dialog, "Show", hWndOwner); flag = 0 == num2; } finally { r.CallAs(typeIFileDialog, dialog, "Unadvise", num); GC.KeepAlive(pfde); } return flag; }