本文整理汇总了C#中IFileDialog.SetFileTypeIndex方法的典型用法代码示例。如果您正苦于以下问题:C# IFileDialog.SetFileTypeIndex方法的具体用法?C# IFileDialog.SetFileTypeIndex怎么用?C# IFileDialog.SetFileTypeIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileDialog
的用法示例。
在下文中一共展示了IFileDialog.SetFileTypeIndex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SyncFileTypeComboToDefaultExtension
/// <summary>
/// Tries to set the File(s) Type Combo to match the value in
/// 'DefaultExtension'. Only doing this if 'this' is a Save dialog
/// as it makes no sense to do this if only Opening a file.
/// </summary>
///
/// <param name="dialog">The native/IFileDialog instance.</param>
///
private void SyncFileTypeComboToDefaultExtension(IFileDialog dialog)
{
if (DefaultExtension == null ||
filters.Count <= 0)
{
return;
}
CommonFileDialogFilter filter = null;
for (uint filtersCounter = 0; filtersCounter < filters.Count; filtersCounter++)
{
filter = (CommonFileDialogFilter)filters[(int)filtersCounter];
if (filter.Extensions.Contains(DefaultExtension))
{
// set the docType combo to match this
// extension. property is a 1-based index.
dialog.SetFileTypeIndex(filtersCounter + 1);
// we're done, exit for
break;
}
}
}
示例2: SyncFileTypeComboToDefaultExtension
/// <summary>
/// Tries to set the File(s) Type Combo to match the value in
/// 'DefaultExtension'. Only doing this if 'this' is a Save dialog
/// as it makes no sense to do this if only Opening a file.
/// </summary>
///
/// <param name="dialog">The native/IFileDialog instance.</param>
///
private void SyncFileTypeComboToDefaultExtension(IFileDialog dialog)
{
// make sure it's a Save dialog and that there is a default
// extension to sync to.
if (!(this is CommonSaveFileDialog) || DefaultExtension == null ||
filters.Count <= 0)
{
return;
}
// The native version of SetFileTypeIndex() requires an
// unsigned integer as its parameter. This (having it be defined
// as a uint right up front) avoids a cast, and the potential
// problems of casting a signed value to an unsigned one.
uint filtersCounter = 0;
CommonFileDialogFilter filter = null;
for (filtersCounter = 0; filtersCounter < filters.Count;
filtersCounter++)
{
filter = (CommonFileDialogFilter)filters[(int)filtersCounter];
if (filter.Extensions.Contains(DefaultExtension))
{
// set the docType combo to match this
// extension. property is a 1-based index.
dialog.SetFileTypeIndex(filtersCounter + 1);
// we're done, exit for
break;
}
}
}
示例3: SyncFileTypeComboToDefaultExtension
/// <summary>
/// Tries to set the File(s) Type Combo to match the value in
/// 'DefaultExtension'. Only doing this if 'this' is a Save dialog
/// as it makes no sense to do this if only Opening a file.
/// </summary>
///
/// <param name="dialog">The native/IFileDialog instance.</param>
///
private void SyncFileTypeComboToDefaultExtension(IFileDialog dialog)
{
// make sure it's a Save dialog and that there is a default
// extension to sync to.
if (!(this is CommonSaveFileDialog) || DefaultExtension == null ||
filters.Count <= 0)
{
return;
}
for (uint filtersCounter = 0; filtersCounter < filters.Count; filtersCounter++)
{
CommonFileDialogFilter filter = (CommonFileDialogFilter)filters[(int)filtersCounter];
if (filter.Extensions.Contains(DefaultExtension))
{
// set the docType combo to match this
// extension. property is a 1-based index.
dialog.SetFileTypeIndex(filtersCounter + 1);
// we're done, exit for
break;
}
}
}
示例4: PrepareVistaDialog
internal virtual void PrepareVistaDialog(IFileDialog dialog)
{
dialog.SetDefaultExtension(DefaultExt);
dialog.SetFileName(CriticalFileName);
if (!string.IsNullOrEmpty(InitialDirectory))
{
IShellItem initialDirectory = ShellUtil.GetShellItemForPath(InitialDirectory);
if (initialDirectory != null)
{
// Setting both of these so the dialog doesn't display errors when a remembered folder is missing.
dialog.SetDefaultFolder(initialDirectory);
dialog.SetFolder(initialDirectory);
}
}
dialog.SetTitle(Title);
// Force no mini mode for the SaveFileDialog.
// Only accept physically backed locations.
FOS options = ((FOS)Options & c_VistaFileDialogMask) | FOS.DEFAULTNOMINIMODE | FOS.FORCEFILESYSTEM;
dialog.SetOptions(options);
COMDLG_FILTERSPEC[] filterItems = GetFilterItems(Filter);
if (filterItems.Length > 0)
{
dialog.SetFileTypes((uint)filterItems.Length, filterItems);
dialog.SetFileTypeIndex(unchecked((uint)FilterIndex));
}
IList<FileDialogCustomPlace> places = CustomPlaces;
if (places != null && places.Count != 0)
{
foreach (FileDialogCustomPlace customPlace in places)
{
IShellItem shellItem = ResolveCustomPlace(customPlace);
if (shellItem != null)
{
try
{
dialog.AddPlace(shellItem, FDAP.BOTTOM);
}
catch (ArgumentException)
{
// The dialog doesn't allow some ShellItems to be set as Places (like device ports).
// Silently ---- errors here.
}
}
}
}
}
示例5: SetDialogProperties
internal virtual void SetDialogProperties(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(NativeMethods.CreateItemFromParsingName(parent));
dialog.SetFileName(folder);
}
}
// Set the filter
if( !string.IsNullOrEmpty(_filter) )
{
string[] filterElements = _filter.Split(new char[] { '|' });
NativeMethods.COMDLG_FILTERSPEC[] filter = new NativeMethods.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) )
{
IShellItem item = NativeMethods.CreateItemFromParsingName(_initialDirectory);
dialog.SetDefaultFolder(item);
}
// ShowHelp
if( _showHelp )
{
IFileDialogCustomize customize = (IFileDialogCustomize)dialog;
customize.AddPushButton(HelpButtonId, "&Help");
}
if( !string.IsNullOrEmpty(_title) )
{
dialog.SetTitle(_title);
}
dialog.SetOptions((_options | NativeMethods.FOS.FOS_FORCEFILESYSTEM));
}