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(); } } }
private void btnAdd_Click(object sender, System.EventArgs e) { attachmentDlg.Reset(); attachmentDlg.Multiselect = true; attachmentDlg.CheckFileExists = true; attachmentDlg.CheckPathExists = true; if (attachmentDlg.ShowDialog() != DialogResult.OK) { return; } string [] attachments = attachmentDlg.FileNames; int nLen = attachments.Length; for (int i = 0; i < nLen; i++) { m_arAttachment.Add(attachments[i]); string fileName = attachments[i]; int pos = fileName.LastIndexOf("\\"); if (pos != -1) { fileName = fileName.Substring(pos + 1); } textAttachments.Text += fileName; textAttachments.Text += ";"; } }
public static void PrepareToSelectABTAGameRunFile(System.Windows.Forms.OpenFileDialog dialog, string initFilePath) { dialog.Reset(); dialog.Title = "Select Alien Breed: Tower Assault run file..."; dialog.Filter = "Exe file (*.exe)|*.exe|BAT file (*.bat)|*.bat"; dialog.FileName = initFilePath; }
private void BtnOpenMNistClick(object sender, EventArgs e) { var dialog = new OpenFileDialog(); dialog.Title = "Выберите файл изображений"; dialog.Filter = "Файл изображений|*.idx3-ubyte"; if (dialog.ShowDialog() != DialogResult.OK) return; var imagesPath = dialog.FileName; dialog.Reset(); dialog.Title = "Выберите файл подписей"; dialog.Filter = "Файл подписей|*.idx1-ubyte"; if (dialog.ShowDialog() != DialogResult.OK) return; var labelsPath = dialog.FileName; nistImages = MNistFileManager.GetImageSet(labelsPath, imagesPath); udMNistImageIndex.Maximum = nistImages.Length - 1; lblMNistInfo.Text = string.Format("{0} элементов", nistImages.Length); lblMNistInfo.ForeColor = Color.DarkGreen; UdMNistImageIndexValueChanged(udMNistImageIndex, EventArgs.Empty); DisablePanels(PanelsState.AllEnabled); }
private void NEWTProfileButton_Click( object sender, EventArgs e ) { if (_fileProfileDialogOpened) return; _fileProfileDialogOpened = true; string newtFolder = Environment.GetEnvironmentVariable("ProgramFiles") + @"\Network Emulator for Windows Toolkit\"; if (newtFolder.IndexOf("(x86)", StringComparison.Ordinal) > 0) newtFolder = newtFolder.Replace("Program Files (x86)", "Program Files"); string newtProfileFolder = newtFolder + "profiles\\"; _openProfileFileDialog = new OpenFileDialog(); _openProfileFileDialog.Reset(); _openProfileFileDialog.Filter = "XML files(*.xml)|*.xml|config files(*.config)|*.config"; _openProfileFileDialog.FilterIndex = 1; _openProfileFileDialog.Title = "Load Network Emulation Congifuration File..."; _openProfileFileDialog.InitialDirectory = newtProfileFolder; _openProfileFileDialog.RestoreDirectory = true; DialogResult result = _openProfileFileDialog.ShowDialog(); if(result == DialogResult.OK) { _newtProfileFile = _openProfileFileDialog.FileName; int index = _newtProfileFile.LastIndexOf(@"\", StringComparison.Ordinal); _newtProfileFileName = _newtProfileFile.Substring(index + 1).Replace(".xml",""); this.NetProfileTextBox.Text = _newtProfileFileName; } _fileProfileDialogOpened = false; }
private void OpenButton_Click( object sender, EventArgs e ) { if (_fileDialogOpened) return; _fileDialogOpened = true; _openFileDialog = new OpenFileDialog(); _openFileDialog.Reset(); _openFileDialog.DefaultExt = ".xml"; _openFileDialog.InitialDirectory = _defaultFolder; _openFileDialog.RestoreDirectory = true; _openFileDialog.Filter = "XML files(*.xml)|*.xml|config files(*.config)|*.config"; _openFileDialog.FilterIndex = 1; _openFileDialog.Title = "Load Custom Bedlam Config File..."; DialogResult result = _openFileDialog.ShowDialog(); if(result == DialogResult.OK) { string openFileName = _openFileDialog.FileName; try { Stream s = _openFileDialog.OpenFile(); LoadBedlamValuesFromConfig(s); s.Close(); } catch(Exception ex) { MessageBox.Show("Oops!\n" + ex.Message + "\n" + openFileName); } } _fileDialogOpened = false; }
public void OpenFileDialogTest () { ofd = new OpenFileDialog (); Assert.IsTrue (ofd.AddExtension, "#11"); Assert.IsTrue (ofd.CheckFileExists, "#12"); Assert.IsTrue (ofd.CheckPathExists, "#13"); Assert.AreEqual ("", ofd.DefaultExt, "#14"); Assert.IsTrue (ofd.DereferenceLinks, "#15"); Assert.AreEqual ("", ofd.FileName, "#16"); Assert.IsNotNull (ofd.FileNames, "#17"); Assert.AreEqual (0, ofd.FileNames.Length, "#17a"); Assert.AreEqual ("", ofd.Filter, "#18"); Assert.AreEqual (1, ofd.FilterIndex, "#19"); Assert.AreEqual ("", ofd.InitialDirectory, "#20"); Assert.IsFalse (ofd.Multiselect, "#21"); Assert.IsFalse (ofd.ReadOnlyChecked, "#22"); Assert.IsFalse (ofd.RestoreDirectory, "#23"); Assert.IsFalse (ofd.ShowHelp, "#24"); Assert.IsFalse (ofd.ShowReadOnly, "#25"); Assert.AreEqual ("", ofd.Title, "#26"); Assert.IsTrue (ofd.ValidateNames, "#27"); Assert.AreEqual ("System.Windows.Forms.OpenFileDialog: Title: , FileName: ", ofd.ToString (), "#28"); ofd.DefaultExt = ".TXT"; Assert.AreEqual ("TXT", ofd.DefaultExt, "#29"); ofd.Filter = null; Assert.AreEqual ("", ofd.Filter, "#30"); ofd.Filter = "Text (*.txt)|*.txt|All (*.*)|*.*"; try { ofd.Filter = "abcd"; } catch (Exception) { } Assert.AreEqual ("Text (*.txt)|*.txt|All (*.*)|*.*", ofd.Filter, "#30a"); ofd.FilterIndex = 10; Assert.AreEqual (10, ofd.FilterIndex, "#30aa"); ofd.Filter = null; Assert.AreEqual ("", ofd.Filter, "#30b"); Assert.AreEqual (10, ofd.FilterIndex, "#30ba"); string current_path = Environment.CurrentDirectory; string current_file = Path.Combine(current_path, "test_file"); if (!File.Exists (current_file)) File.Create (current_file); ofd.FileName = current_file; Assert.AreEqual (current_file, ofd.FileName, "#31"); string[] file_names = ofd.FileNames; Assert.AreEqual (current_file, file_names [0], "#32"); ofd.Title = "Test"; Assert.AreEqual ("System.Windows.Forms.OpenFileDialog: Title: Test, FileName: " + current_file, ofd.ToString (), "#33"); ofd.FileName = null; Assert.AreEqual ("", ofd.FileName, "#33a"); Assert.IsNotNull (ofd.FileNames, "#33b"); Assert.AreEqual (0, ofd.FileNames.Length, "#33c"); ofd.Reset (); // check again Assert.IsTrue (ofd.AddExtension, "#34"); Assert.IsTrue (ofd.CheckFileExists, "#35"); Assert.IsTrue (ofd.CheckPathExists, "#36"); Assert.AreEqual ("", ofd.DefaultExt, "#37"); Assert.IsTrue (ofd.DereferenceLinks, "#38"); Assert.AreEqual ("", ofd.FileName, "#39"); Assert.IsNotNull (ofd.FileNames, "#40"); Assert.AreEqual ("", ofd.Filter, "#41"); Assert.AreEqual (1, ofd.FilterIndex, "#42"); Assert.AreEqual ("", ofd.InitialDirectory, "#43"); Assert.IsFalse (ofd.Multiselect, "#44"); Assert.IsFalse (ofd.ReadOnlyChecked, "#45"); Assert.IsFalse (ofd.RestoreDirectory, "#46"); Assert.IsFalse (ofd.ShowHelp, "#47"); Assert.IsFalse (ofd.ShowReadOnly, "#48"); Assert.AreEqual ("", ofd.Title, "#49"); Assert.IsTrue (ofd.ValidateNames, "#50"); Assert.AreEqual ("System.Windows.Forms.OpenFileDialog: Title: , FileName: ", ofd.ToString (), "#60"); }
private void fileLoad() { OpenFileDialog open = new OpenFileDialog(); Stream stre; open.DefaultExt = "txt"; open.Filter = "文字檔(*.txt)|*.txt"; open.ReadOnlyChecked = true; if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK) { is_file_path2 = open.FileName; stre = open.OpenFile(); try { richTextBox1.LoadFile(stre, RichTextBoxStreamType.PlainText); } catch (Exception file_exce) { MessageBox.Show(file_exce.ToString(), "錯誤訊息"); } finally { //關閉stream才算關閉這個檔案,只有對openfiledialog做dispose是沒用的, //還是會出現有人正在使用這個檔案 stre.Close(); open.Reset(); open.Dispose(); open = null; } } }
private void btnRetriveFileNames_Click(object sender, System.EventArgs e) { try { // You may ! always want to do this, // but you can set the initial directory. // In this example, the code only // sets this property if you've // set the DefaultFolder value // since the last time opening // the dialog box. if you don't // call the Reset method, your // initial directory won't affect // the dialog box, if you've already // selected a file using it. odlgFileNames.Reset(); odlgFileNames.InitialDirectory = @"C:\"; // Add default extension to file name if the user // doesn't type it. // The default is true. odlgFileNames.AddExtension = true; // Check to ensure that the selected // file exists. Dialog box displays // a warning otherwise. // The default is true. odlgFileNames.CheckFileExists = true; // Check to ensure that the selected // path exists. Dialog box displays // a warning otherwise. // The default is true. odlgFileNames.CheckPathExists = true; // Get or set default extension. Doesn't // include the leading ".". // The default is "". odlgFileNames.DefaultExt = "txt"; // return the file referenced by a link? if // false, simply returns the selected link // file. if true, returns the file linked to // the LNK file. // The default is true. odlgFileNames.DereferenceLinks = true; // Just in VB6, use a set of pairs // of filters, separated with "|". Each // pair consists of a description|file spec. // Use a "|" between pairs. No need to put a // trailing "|". You can set the FilterIndex // property well, to select the default // filter. Amazingly, the first filter is // numbered 1 (! 0). The default is 1. // The default is "". odlgFileNames.Filter = "Text files (*.txt)|*.txt|" + "All files|*.*"; // if you want to allow users to select // more than one file, set this to true. // if you set this to true, retrieve // the selected files using the FileNames // property of the dialog box. // The default is false. odlgFileNames.Multiselect = true; // Restore the original directory when done selecting // a file? if false, the current directory changes // to the directory in which you selected the file. // Set this to true to put the current folder back // where it was when you started. // The default is false. odlgFileNames.RestoreDirectory = true; // Show the Help button and Read-Only checkbox? // The Default for each is false. odlgFileNames.ShowHelp = true; odlgFileNames.ShowReadOnly = false; // Start out with the read-only check box checked? // This only make sense if ShowReadOnly is true. // The default is false. // .ReadOnlyChecked = false // The default is "". odlgFileNames.Title = "Select a file"; // Only accept valid Win32 file names? // The default is true. odlgFileNames.ValidateNames = true; if (odlgFileNames.ShowDialog() == DialogResult.OK) { // You have a choice here. You can either // use the FileName or FileNames properties to get the name // you selected, or you can use the OpenFile // method to open the file a read-only Stream. lstFiles.DataSource = odlgFileNames.FileNames; // You could also write code like this, // to loop through the selected file names: //strName string //foreach(strName In .FileNames // lstFiles.Items.Add(strName) //Next } } catch (Exception exp) { MessageBox.Show(exp.Message, this.Text); } }
public override void Reset() { dialog.Reset(); }
public void Reset() { _openFileDialog.Reset(); }
private void btnImgFileName_Click(object sender, EventArgs e) { picSource.Image = null; picCaptche.Image = null; OpenFileDialog open = new OpenFileDialog(); open.Reset(); open.ShowDialog(); txtImageFileName.Text = open.FileName; if (txtImageFileName.Text.Trim() != string.Empty) { try { picSource.Image = Image.FromFile(txtImageFileName.Text.Trim()); bit = new Bitmap(picSource.Image); } catch(Exception ex) { MessageBox.Show(ex.Message, "郁闷!你选的是图片吗?"); } } }
//选择图像 private void button1_Click(object sender, EventArgs e) { OpenFileDialog open = new OpenFileDialog(); open.Reset(); open.RestoreDirectory = true; open.ShowDialog(); txtUrlImg.Text = open.FileName; if (txtUrlImg.Text.Trim() != string.Empty) { try { picSource.Image = Image.FromFile(txtUrlImg.Text); img = new Bitmap(picSource.Image); if (img != null) { YanMoCaptche yanmo = new YanMoCaptche(); img = yanmo.GrayImage(img, 180); //灰度化 img = yanmo.ClearNoise(img); //去噪 bit = yanmo.InciseImage(img); //切割 for (int i = 0; i < bit.Length; i++) //冲洗 { //bit[i].Save("S" + i.ToString() + ".bmp"); bit[i] = yanmo.RinseImage(bit[i]); //bit[i].Save("H" + i.ToString() + ".bmp"); } pic1.Image = bit[0]; pic2.Image = bit[1]; pic3.Image = bit[2]; pic4.Image = bit[3]; } rtxState.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message, "郁闷!你选的是图片吗?"); } } }