本文整理汇总了C#中System.Windows.Forms.OpenFileDialog.ShowDialog方法的典型用法代码示例。如果您正苦于以下问题:C# OpenFileDialog.ShowDialog方法的具体用法?C# OpenFileDialog.ShowDialog怎么用?C# OpenFileDialog.ShowDialog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.OpenFileDialog
的用法示例。
在下文中一共展示了OpenFileDialog.ShowDialog方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: button3_Click
private void button3_Click(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count != 1)
return;
OpenFileDialog od = new OpenFileDialog();
od.Filter = "Bitmap file (*.bmp)|*.bmp";
od.FilterIndex = 0;
if (od.ShowDialog() == DialogResult.OK)
{
Section s = listView1.SelectedItems[0].Tag as Section;
try
{
Bitmap bmp = new Bitmap(od.FileName);
s.import(bmp);
bmp.Dispose();
pictureBox1.Image = s.image();
listView1.SelectedItems[0].SubItems[3].Text = s.cnt.ToString();
button4.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
示例2: Setup
private void Setup()
{
var configSetup = new NHibernateConfigSetup();
if (!configSetup.VerifyNHConfigFileExist())
{
if (MessageBox.Show("El archivo de conexión a la base de datos no existe\n" +
"para poder hacer uso del sistema por favor importe el archivo.\n\n",
"Inventarios",
MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
{
var ofdBuscarArchivo = new OpenFileDialog
{
InitialDirectory = "c:\\",
Filter = "Data files (*.config)|*.config",
FilterIndex = 2,
RestoreDirectory = false
};
if (ofdBuscarArchivo.ShowDialog() == DialogResult.OK)
{
File.Copy(ofdBuscarArchivo.FileName, "C:\\NHibernateSettings\\" + ofdBuscarArchivo.SafeFileName);
}
if (ofdBuscarArchivo.ShowDialog() == DialogResult.Cancel)
{
Application.Exit();
}
}
else
Application.Exit();
}
else
{
configSetup.InitializeNHibernate();
AutoMapperConfiguration.Configure();
}
}
示例3: button4_Click
private void button4_Click(object sender, EventArgs e)
{
OpenFileDialog fileDia = new OpenFileDialog();
fileDia.Title = "Please select the data.dat file to extract.";
fileDia.Filter = "data.dat|*.dat";
fileDia.DefaultExt = "*.dat";
fileDia.ShowDialog();
string dataPath = fileDia.FileName;
fileDia.Title = "Please select the resource.dat file to extract.";
fileDia.Filter = "resource.dat|*.dat";
fileDia.ShowDialog();
string resourcesPath = fileDia.FileName;
string targetPath = Application.StartupPath;
//System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + "ftldat unpack \"" + dataPath + "\" \"" + targetPath + "\"\\data\\");
System.Diagnostics.Process.Start("cmd", "/c " + "ftldat unpack \"" + dataPath + "\" \"" + targetPath + "\\data\"");
System.Diagnostics.Process.Start("cmd", "/c " + "ftldat unpack \"" + resourcesPath + "\" \"" + targetPath + "\\resource\"");
tbPathData.Text = targetPath + "\\data\\";
dataPath = targetPath + "\\data\\";
tbPathResources.Text = targetPath + "\\resource\\";
resPath = targetPath + "\\resource\\";
UpdatePaths();
fileDia.Dispose();
}
示例4: OnClick
public void OnClick()
{
if (Application.platform == RuntimePlatform.WindowsPlayer ||
Application.platform == RuntimePlatform.WindowsEditor)
{
System.Windows.Forms.OpenFileDialog opDialog = new System.Windows.Forms.OpenFileDialog();
opDialog.DefaultExt = "*.ogg";
opDialog.Filter = "Audio 파일(*.ogg) |*.ogg|모든 파일(*.*)|*.*";
if (opDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (opDialog.CheckFileExists)
{
if (_mainAudioSource != null)
{
AudioLoad(opDialog.FileName);
}
else if (Debug.isDebugBuild)
{
Debug.LogError("Main Audio Source is NULL!");
}
}
else if (Debug.isDebugBuild)
{
Debug.LogError("Audio File was not Exists!");
}
}
opDialog.Reset();
opDialog.DefaultExt = "*.txt";
opDialog.Filter = "Script Txt 파일(*.txt) |*.txt|모든 파일(*.*)|*.*";
// Load Script
if (opDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (opDialog.CheckFileExists)
{
if (MkManager.Instance != null)
{
MkManager.Instance.AnimeScriptParse(opDialog.FileName);
}
else if (Debug.isDebugBuild)
{
Debug.LogError("MkParser was not Exists!");
}
}
else if (Debug.isDebugBuild)
{
Debug.LogError("Script File was not Exists!");
}
_isLoaded = true;
}
if (_mainAudioSource != null)
{
_mainAudioSource.Play();
}
}
}
示例5: btnOpenXml_Click
private void btnOpenXml_Click(object sender, EventArgs e)
{
LoadXML xml = new LoadXML();
string pfad = null;
//Öffnet OpenFileDialog
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
DialogResult result = openFileDialog1.ShowDialog();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if (openFileDialog1.OpenFile() != null)
{
//Öffnet Explorer und ermittelt den Eingegebenen Dateipfad
string file = openFileDialog1.FileName;
try
{
pfad = openFileDialog1.FileName;
}
//TODO: Ausnahme hinzufügen
catch (IOException)
{
}
}
//Dateipfad wird an die Klasse ladeXML übergeben
Console.WriteLine(result);
Console.WriteLine(pfad);
xml.ladeXML(pfad);
}
}
示例6: Main
static void Main(string[] args)
{
//Excel worksheet combine example
//You will be prompted to select two Excel files. test.xls will be created that combines the sheets
//Note: This example does not check for duplicate sheet names. Your test files should have different sheet names.
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Excel document (*.xls)|*.xls";
ofd.Title = "Select first Excel document";
if (ofd.ShowDialog() == DialogResult.OK)
{
HSSFWorkbook book1 = new HSSFWorkbook(new FileStream(ofd.FileName, FileMode.Open));
ofd.Title = "Select second Excel document";
if (ofd.ShowDialog() == DialogResult.OK)
{
HSSFWorkbook book2 = new HSSFWorkbook(new FileStream(ofd.FileName, FileMode.Open));
HSSFWorkbook product = new HSSFWorkbook();
for (int i = 0; i < book1.NumberOfSheets; i++)
{
HSSFSheet sheet1 = book1.GetSheetAt(i) as HSSFSheet;
sheet1.CopyTo(product, sheet1.SheetName, true, true);
}
for (int j = 0; j < book2.NumberOfSheets; j++)
{
HSSFSheet sheet2 = book2.GetSheetAt(j) as HSSFSheet;
sheet2.CopyTo(product, sheet2.SheetName, true, true);
}
product.Write(new FileStream("test.xls", FileMode.Create, FileAccess.ReadWrite));
}
}
}
示例7: FileSelectFile
// TODO: organise Dialogs.cs
#region FileSelectFile
/// <summary>
/// Displays a standard dialog that allows the user to open or save files.
/// </summary>
/// <param name="OutputVar">The user selected files.</param>
/// <param name="Options">
/// <list type="bullet">
/// <item><term>M</term>: <description>allow muliple files to be selected.</description></item>
/// <item><term>S</term>: <description>show a save as dialog rather than a file open dialog.</description></item>
/// <item><term>1</term>: <description>only allow existing file or directory paths.</description></item>
/// <item><term>8</term>: <description>prompt to create files.</description></item>
/// <item><term>16:</term>: <description>prompt to overwrite files.</description></item>
/// <item><term>32</term>: <description>follow the target of a shortcut rather than using the shortcut file itself.</description></item>
/// </list>
/// </param>
/// <param name="RootDir">The file path to initially select.</param>
/// <param name="Prompt">Text displayed in the window to instruct the user what to do.</param>
/// <param name="Filter">Indicates which types of files are shown by the dialog, e.g. <c>Audio (*.wav; *.mp2; *.mp3)</c>.</param>
public static void FileSelectFile(out string OutputVar, string Options, string RootDir, string Prompt, string Filter)
{
bool save = false, multi = false, check = false, create = false, overwite = false, shortcuts = false;
Options = Options.ToUpperInvariant();
if (Options.Contains("M"))
{
Options = Options.Replace("M", string.Empty);
multi = true;
}
if (Options.Contains("S"))
{
Options = Options.Replace("S", string.Empty);
save = true;
}
int result;
if (int.TryParse(Options.Trim(), out result))
{
if ((result & 1) == 1 || (result & 2) == 2)
check = true;
if ((result & 8) == 8)
create = true;
if ((result & 16) == 16)
overwite = true;
if ((result & 32) == 32)
shortcuts = true;
}
ErrorLevel = 0;
OutputVar = null;
if (save)
{
var saveas = new SaveFileDialog { CheckPathExists = check, CreatePrompt = create, OverwritePrompt = overwite, DereferenceLinks = shortcuts, Filter = Filter };
var selected = dialogOwner == null ? saveas.ShowDialog() : saveas.ShowDialog(dialogOwner);
if (selected == DialogResult.OK)
OutputVar = saveas.FileName;
else
ErrorLevel = 1;
}
else
{
var open = new OpenFileDialog { Multiselect = multi, CheckFileExists = check, DereferenceLinks = shortcuts, Filter = Filter };
var selected = dialogOwner == null ? open.ShowDialog() : open.ShowDialog(dialogOwner);
if (selected == DialogResult.OK)
OutputVar = multi ? string.Join("\n", open.FileNames) : open.FileName;
else
ErrorLevel = 1;
}
}
示例8: Main
static void Main()
{
var openFileDialog = new OpenFileDialog();
openFileDialog.Title = "Select a file from the files to assemble";
openFileDialog.InitialDirectory = new DirectoryInfo("../../../").FullName;
string filePath;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
filePath = openFileDialog.FileName;
}
else
{
throw new ApplicationException("No file selected");
}
string slicesDirectroy = new FileInfo(filePath).DirectoryName;
List<FileInfo> files = Directory
.GetFiles(slicesDirectroy)
.OrderBy(name => name)
.Select(file => new FileInfo(file))
.ToList();
openFileDialog.Title = "Select a directroy to save the assembled file";
string outputDirectory;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
filePath = openFileDialog.FileName;
}
else
{
throw new ApplicationException("No file selected");
}
Console.WriteLine("Assembling Files...");
var sw = new Stopwatch();
sw.Start();
Task asyncTask = AssembleAsync(files, "../../../Assembled");
int left = Console.CursorLeft;
double currentSecond = sw.Elapsed.TotalSeconds;
while (!asyncTask.IsCompleted)
{
if (sw.Elapsed.TotalSeconds >= currentSecond + 1)
{
currentSecond = sw.Elapsed.TotalSeconds;
Console.Write("{0}", Math.Floor(currentSecond));
Console.CursorLeft = left;
}
}
Console.WriteLine("Completed... {0}", sw.Elapsed);
}
示例9: GetPathFromDialog
public static string GetPathFromDialog()
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Text files (*.csv)|*.csv";
openFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
if (openFileDialog.ShowDialog() == DialogResult.OK || openFileDialog.ShowDialog() == DialogResult.Yes)
{
return openFileDialog.FileName;
}
return null;
}
示例10: btnBrowse_Click
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.ShowDialog();
if (dlg.ShowDialog()== DialogResult.OK )
{
string fileName;
fileName = dlg.FileName;
txtFile.Text = fileName;
btnSend2.Enabled = true;
}
}
示例11: callOpenFileDialog
private static string[] callOpenFileDialog(string startpath, string fileTypes, bool multiSelect, IWin32Window parentForm, ScriptEngine engine)
{
try {
OpenFileDialog dlg = new OpenFileDialog();
dlg.InitialDirectory = startpath;
dlg.Filter = fileTypes;
dlg.Multiselect = multiSelect;
DialogResult result = parentForm == null ? dlg.ShowDialog() : dlg.ShowDialog(parentForm);
return result == DialogResult.OK ? dlg.FileNames : new string[0];
} catch (Exception ex) {
throw ex.convertException(engine);
}
}
示例12: Browse
private void Browse(object sender, EventArgs e)
{
Button b = sender as Button;
TextBox t = b.Tag as TextBox;
OpenFileDialog ofd = new OpenFileDialog();
SaveFileDialog sfd = new SaveFileDialog();
if (t.Name == "txtInput")
{
// ofd
ofd.Filter = "Bitmap Files (*.bmp)|*.bmp";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return;
t.Text = ofd.FileName;
}
else if (t.Name == "txtOutput")
{
if (rdbHide.Checked)
{
// sfd
sfd.Filter = "Bitmap Files (*.bmp)|*.bmp";
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return;
t.Text = sfd.FileName;
}
else
{
// ofd
ofd.Filter = "Bitmap Files (*.bmp)|*.bmp";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return;
t.Text = ofd.FileName;
}
}
else if (t.Name == "txtData")
{
if (rdbHide.Checked)
{
// ofd
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return;
t.Text = ofd.FileName;
}
else
{
// sfd
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return;
t.Text = sfd.FileName;
}
}
}
示例13: button1_Click
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog f = new OpenFileDialog(); //création d'une fenetre d'exploration
f.Title = "Choisir le fichier à importer";
if (f.ShowDialog() == DialogResult.OK) //si fond est coché
{
f.Filter = "Images(*.ZIP)|*.ZIP"; //filtre le type de fichier autorisé
f.ShowDialog(); //affiche la boite de dialogue
theme = f.FileName;
}
else
{
MessageBox.Show("Erreur");
}
}
示例14: Main
private static void Main()
{
Console.WriteLine("Hello World!");
OpenFileDialog dlgOpen = new OpenFileDialog();
Console.WriteLine("Dumaan na dito!");
dlgOpen.ShowDialog();
Console.WriteLine("Ito na ulit!");
if (dlgOpen.ShowDialog() == DialogResult.OK)
{
string s = dlgOpen.FileName;
Console.WriteLine("Filename " + s);
Console.WriteLine(" Created at " + File.GetCreationTime(s));
Console.WriteLine(" Accessed at " + File.GetLastAccessTime(s));
}
}
示例15: LoadNewPlugin
public static void LoadNewPlugin(IAutoWikiBrowser awb)
{
OpenFileDialog pluginOpen = new OpenFileDialog();
if (string.IsNullOrEmpty(LastPluginLoadedLocation))
LoadLastPluginLoadedLocation();
pluginOpen.InitialDirectory = string.IsNullOrEmpty(LastPluginLoadedLocation) ? Application.StartupPath : LastPluginLoadedLocation;
pluginOpen.DefaultExt = "dll";
pluginOpen.Filter = "DLL files|*.dll";
pluginOpen.CheckFileExists = pluginOpen.Multiselect = /*pluginOpen.AutoUpgradeEnabled =*/ true;
pluginOpen.ShowDialog();
if (!string.IsNullOrEmpty(pluginOpen.FileName))
{
string newPath = Path.GetDirectoryName(pluginOpen.FileName);
if (LastPluginLoadedLocation != newPath)
{
LastPluginLoadedLocation = newPath;
SaveLastPluginLoadedLocation();
}
}
Plugin.LoadPlugins(awb, pluginOpen.FileNames, true);
}