本文整理汇总了C#中System.Windows.Forms.OpenFileDialog.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# OpenFileDialog.GetType方法的具体用法?C# OpenFileDialog.GetType怎么用?C# OpenFileDialog.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.OpenFileDialog
的用法示例。
在下文中一共展示了OpenFileDialog.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Show
public static string[] Show(Form parent)
{
if (Environment.OSVersion.Version.Major >= 6){ // vista and newer
try{
OpenFileDialog dialog = new OpenFileDialog{
Filter = Lang.Get["DialogFilterFolders"]+FilterFolders,
CheckFileExists = false,
CheckPathExists = true,
DereferenceLinks = true,
AddExtension = false,
Multiselect = true,
AutoUpgradeEnabled = true
};
Assembly assembly = LoadAssembly("System.Windows.Forms");
Type ifdType = assembly.GetType("System.Windows.Forms.FileDialogNative").GetNestedType("IFileDialog", BindingFlags.NonPublic);
Type fdType = typeof(FileDialog);
Type dialogType = dialog.GetType();
const BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
var vistaDialog = dialogType.GetMethod("CreateVistaDialog", flags).Invoke(dialog, new object[0]);
dialogType.GetMethod("OnBeforeVistaDialog", flags).Invoke(dialog, new object[]{ vistaDialog });
uint opts = (uint)fdType.GetMethod("GetOptions", flags).Invoke(dialog, new object[0]);
ifdType.GetMethod("SetOptions", flags).Invoke(vistaDialog, new object[]{ opts | 32u }); // 32u = FOS_PICKFOLDERS
object events = fdType.GetNestedType("VistaDialogEvents", flags).GetConstructors()[0].Invoke(new object[]{ dialog });
object[] parameters = { events, (uint)0 };
ifdType.GetMethod("Advise").Invoke(vistaDialog, parameters);
uint id = (uint)parameters[1];
try{
ifdType.GetMethod("Show").Invoke(vistaDialog, new object[]{ parent.Handle });
}finally{
ifdType.GetMethod("Unadvise").Invoke(vistaDialog, new object[]{ id });
GC.KeepAlive(events);
}
return dialog.FileNames;
}catch(Exception e){
Debug.Write(e.ToString());
}
}
var oldDialog = new FolderBrowserDialog{ ShowNewFolderButton = false };
return oldDialog.ShowDialog(parent) == DialogResult.OK ? new string[]{ oldDialog.SelectedPath } : new string[0];
}