/// <summary> /// Диалог открытия\сохранения файла /// </summary> /// <param name="filter">строка фильтра в формате "XML files (*.xml)|*.xml"</param> /// <param name="filename">имя файла, может быть null</param> /// <param name="isOpen">если true то открываеться диалог открытия, иначе диалог сохранения</param> /// <returns>возвращает полный путь к файлу, иначе null </returns> public static string OpenFile(string filter, string filename = null, bool isOpen = true) { string pt = null; if (filter == null) { filter = DefaultFilers; } System.Windows.Forms.FileDialog FileDialog = null; if (isOpen) { FileDialog = new System.Windows.Forms.OpenFileDialog(); } else { FileDialog = new System.Windows.Forms.SaveFileDialog(); //openFileDialog1.InitialDirectory = System.; if (filename != null) { FileDialog.FileName = filename; } } FileDialog.Filter = filter; FileDialog.FilterIndex = 1; FileDialog.RestoreDirectory = true; if (FileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { pt = FileDialog.FileName; } FileDialog.Dispose(); return(pt); }
// TODO: // Get the file name and path from dialog input public static string GetFilePath(System.Windows.Forms.FileDialog file) { file.ShowDialog(); // release resource from FileDialog // dialog hangs when running and closing window multiple times without Dispose() method file.Dispose(); return(file.InitialDirectory + file.FileName); }
public static System.Windows.Forms.FileDialog SetSelectedFile(this System.Windows.Forms.FileDialog dialog, string file_path) { string file_name = string.Empty; string initial_directory = System.IO.Directory.Exists(file_path) ? file_path : (System.IO.File.Exists(file_path) ? System.IO.Path.GetDirectoryName(file_path) : file_path); dialog.FileName = file_name; dialog.InitialDirectory = initial_directory; return(dialog); }
private void handleDialog(System.Windows.Forms.FileDialog dialog, Action <String> pathAction) { dialog.Filter = "Sudoku (*.sudoku)|*.sudoku"; dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { pathAction.Invoke(dialog.FileName); } dialog.Dispose(); }
public FileMolPreview(System.Windows.Forms.FileDialog fc) : base(200, 200, true) { //UPGRADE_ISSUE: Method 'javax.swing.JComponent.addPropertyChangeListener' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaxswingJComponentaddPropertyChangeListener_javabeansPropertyChangeListener'" // TODO: fc.addPropertyChangeListener(this); // setBackground(Color.White); this.BackColor = Color.White; SetBorder(true); SetToolCursor(); SetEditable(false); }
// Constructor public GetFileNameClass(eFileDialog dlg) { switch ((int)dlg) { case 0: _oFileDialog = new System.Windows.Forms.OpenFileDialog(); break; case 1: _oFileDialog = new System.Windows.Forms.SaveFileDialog(); break; default: throw new ApplicationException("GetFileNameClass incorrect parameter"); } }
static public bool DialogResultIsOK(System.Windows.Forms.FileDialog ofd, string filter) { #if WPF4 throw new NotImplementedException("hehaw (not implemented)."); #else if (filter != null) { ofd.Filter = filter; } return(ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK); #endif }
/// <summary> /// Ask user for a filename to open on Windows. /// </summary> /// <param name="selectMultiple">Allow the user to select multiple files?</param> private string[] WindowsFileDialog(bool selectMultiple) { System.Windows.Forms.FileDialog dialog = null; if (Action == FileActionType.Open) { dialog = new System.Windows.Forms.OpenFileDialog(); (dialog as System.Windows.Forms.OpenFileDialog).Multiselect = selectMultiple; } else if (Action == FileActionType.Save) { dialog = new System.Windows.Forms.SaveFileDialog(); } else if (Action == FileActionType.SelectFolder) { return(WindowsDirectoryDialog(selectMultiple)); } dialog.Title = Prompt; string filterString = String.Empty; if (!string.IsNullOrEmpty(FileType)) { if (FileType.Contains("|")) { filterString = FileType; } else { filterString = FileType + "|" + FileType; } if (!filterString.EndsWith("|")) { filterString += "|"; } } dialog.Filter = filterString + "All files (*.*)|*.*"; // This almost works, but Windows is buggy. // If the file name is long, it doesn't display in a sensible way. ¯\_(ツ)_/¯ dialog.InitialDirectory = InitialDirectory; dialog.FileName = null; string[] fileNames = new string[0]; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { fileNames = dialog.FileNames; } dialog = null; return(fileNames); }
public MainWindow() { timeSpent = new Stopwatch(); InitializeComponent(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.openFileDialog1.DefaultExt = "dbf"; this.openFileDialog1.Filter = "Question Bank Files|*.qbf"; this.openFileDialog1.InitialDirectory = "C:\\"; this.openFileDialog1.Title = "Open Question Bank File"; collapse.IsChecked = true; collapse1.IsChecked = false; collapse2.IsChecked = false; }
public static string SelectedFilter(this System.Windows.Forms.FileDialog dialog) { string[] filters = dialog.Filter.Split('|'); int index = dialog.FilterIndex; if (0 <= index && index < filters.Length) { return(filters[index]); } else { return(string.Empty); } }
public static void InitWebbOpenFileDialog(System.Windows.Forms.FileDialog fileDialog, string fileName) { fileDialog.Filter = String.Format("Report Files (*.{0},*.repw)|*.{1};*.repw"); try { if (fileName != null && fileName.Length > 0) { string s = System.IO.Path.GetDirectoryName(fileName); if (s.Length > 0) { fileDialog.InitialDirectory = s; } } } catch {} }
private string PromptForFile(FileTypes type, bool existing) { using (System.Windows.Forms.FileDialog fileDialog = existing ? ((System.Windows.Forms.FileDialog) new System.Windows.Forms.OpenFileDialog()) : ((System.Windows.Forms.FileDialog) new System.Windows.Forms.SaveFileDialog())) { switch (type) { case FileTypes.Disc: fileDialog.DefaultExt = "zip"; fileDialog.Filter = "Disc files (*.dsk;*.zip)|*.dsk;*.zip|All files (*.*)|*.*"; break; case FileTypes.Tape: fileDialog.DefaultExt = "zip"; fileDialog.Filter = "Tape files (*.cdt;*.tzx;*.zip)|*.cdt;*.tzx;*.zip|All files (*.*)|*.*"; break; case FileTypes.Machine: fileDialog.DefaultExt = "cpvc"; fileDialog.Filter = "CPvC files (*.cpvc)|*.cpvc|All files (*.*)|*.*"; break; default: throw new Exception(String.Format("Unknown FileTypes value {0}.", type)); } fileDialog.AddExtension = true; string initialFolder = _settings.GetFolder(type); if (initialFolder != null) { fileDialog.InitialDirectory = initialFolder; } System.Windows.Forms.DialogResult result = fileDialog.ShowDialog(); if (result != System.Windows.Forms.DialogResult.OK) { return(null); } // Remember the last folder for the selected filetype. string folder = System.IO.Path.GetDirectoryName(fileDialog.FileName); _settings.SetFolder(type, folder); return(fileDialog.FileName); } }
public static void InitFileDialog(System.Windows.Forms.FileDialog fileDialog, string fileName) { fileDialog.Filter = String.Format("Report Files (*.{0})|*.{1}|" + "All Files (*.*)|*.*", ReportExt, ReportExt); try { if (fileName != null && fileName.Length > 0) { string s = System.IO.Path.GetDirectoryName(fileName); if (s.Length > 0) { fileDialog.InitialDirectory = s; } } } catch {} }
/// <summary> /// Inicializa uma nova instância da classe <see cref="Spartacus.Forms.Filepicker"/>. /// </summary> /// <param name="p_parent">Container pai.</param> /// <param name="p_type">Tipo do diálogo do Filepicker.</param> /// <param name="p_label">Texto exibido no rótulo.</param> /// <param name="p_filter">Filtro de arquivos a serem exibidos no diálogo do Filepicker.</param> public Filepicker(Spartacus.Forms.Container p_parent, Spartacus.Forms.Filepicker.Type p_type, string p_label, string p_filter) : base(p_parent) { this.v_control = new System.Windows.Forms.Panel(); this.SetWidth(p_parent.v_width); this.SetHeight(40); this.SetLocation(0, p_parent.v_offsety); this.v_label = new System.Windows.Forms.Label(); this.v_label.Text = p_label; this.v_label.Location = new System.Drawing.Point(10, 10); this.v_label.AutoSize = true; this.v_label.Parent = this.v_control; this.v_button = new System.Windows.Forms.Button(); this.v_button.Text = "..."; this.v_button.Width = 30; this.v_button.Location = new System.Drawing.Point(this.v_width - 10 - this.v_button.Width, 5); this.v_button.Click += new System.EventHandler(this.OnClick); this.v_button.Parent = this.v_control; this.v_proportion = 40; this.v_textbox = new System.Windows.Forms.TextBox(); this.v_textbox.Location = new System.Drawing.Point((int)(this.v_width * ((double)this.v_proportion / (double)100)), 5); this.v_textbox.Width = this.v_width - 10 - this.v_button.Width - this.v_textbox.Location.X; this.v_textbox.Parent = this.v_control; this.v_type = p_type; if (this.v_type == Spartacus.Forms.Filepicker.Type.OPEN) { this.v_filedialog = new System.Windows.Forms.OpenFileDialog(); } else { this.v_filedialog = new System.Windows.Forms.SaveFileDialog(); } this.v_filedialog.Title = p_label; this.v_filedialog.Filter = p_filter; }
public TestOpenFileDialog(DialogForm form) { _form = form; }
public FileDialogTests() { _dialogForm = MockRepository.GenerateMock <DialogForm>(); }
public FileDialogTests() { _dialogForm = MockRepository.GenerateMock<DialogForm>(); }
public TestOpenFileDialog(DialogForm form) { _form = form; }