/// <summary> /// Displays the progress dialog as a modal dialog. /// </summary> /// <param name="owner">The window that owns the dialog.</param> /// <param name="argument">A parameter for use by the background operation to be executed in the <see cref="DoWork"/> event handler.</param> /// <remarks> /// <para> /// The ShowDialog function for most .Net dialogs will not return until the dialog is closed. However, /// the <see cref="ShowDialog()"/> function for the <see cref="ProgressDialog"/> class will return immediately. /// The parent window will be disabled as with all modal dialogs. /// </para> /// <para> /// Although this function returns immediately, you cannot use the UI thread to do any processing. The dialog /// will not function correctly unless the UI thread continues to handle window messages, so that thread may /// not be blocked by some other activity. All processing related to the progress dialog must be done in /// the <see cref="DoWork"/> event handler. /// </para> /// <para> /// The progress dialog's window will appear in the taskbar. This behaviour is also contrary to most .Net dialogs, /// but is part of the underlying native progress dialog API so cannot be avoided. /// </para> /// <para> /// When possible, it is recommended that you use a modeless dialog using the <see cref="Show()"/> function. /// </para> /// </remarks> /// <exception cref="InvalidOperationException">The animation specified in the <see cref="Animation"/> property /// could not be loaded, or the operation is already running.</exception> public void ShowDialog(IWin32Window owner, object argument) { RunProgressDialog(owner == null ? Natives.GetActiveWindow() : owner.Handle, argument); }
internal virtual void SetDialogProperties(Ookii.Dialogs.Interop.IFileDialog dialog) { uint cookie; dialog.Advise(new VistaFileDialogEvents(this), out cookie); // Set the default file name if (!(_fileNames == null || _fileNames.Length == 0 || string.IsNullOrEmpty(_fileNames[0]))) { string parent = Path.GetDirectoryName(_fileNames[0]); if (parent == null || !Directory.Exists(parent)) { dialog.SetFileName(_fileNames[0]); } else { string folder = Path.GetFileName(_fileNames[0]); dialog.SetFolder(Natives.CreateItemFromParsingName(parent)); dialog.SetFileName(folder); } } // Set the filter if (!string.IsNullOrEmpty(_filter)) { string[] filterElements = _filter.Split(new char[] { '|' }); Natives.COMDLG_FILTERSPEC[] filter = new Natives.COMDLG_FILTERSPEC[filterElements.Length / 2]; for (int x = 0; x < filterElements.Length; x += 2) { filter[x / 2].pszName = filterElements[x]; filter[x / 2].pszSpec = filterElements[x + 1]; } dialog.SetFileTypes((uint)filter.Length, filter); if (_filterIndex > 0 && _filterIndex <= filter.Length) { dialog.SetFileTypeIndex((uint)_filterIndex); } } // Default extension if (_addExtension && !string.IsNullOrEmpty(_defaultExt)) { dialog.SetDefaultExtension(_defaultExt); } // Initial directory if (!string.IsNullOrEmpty(_initialDirectory)) { Interop.IShellItem item = Natives.CreateItemFromParsingName(_initialDirectory); dialog.SetDefaultFolder(item); } // ShowHelp if (_showHelp) { Ookii.Dialogs.Interop.IFileDialogCustomize customize = (Ookii.Dialogs.Interop.IFileDialogCustomize)dialog; customize.AddPushButton(HelpButtonId, "Help"); } if (!string.IsNullOrEmpty(_title)) { dialog.SetTitle(_title); } dialog.SetOptions((_options | Natives.FOS.FOS_FORCEFILESYSTEM)); }