protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var selectDwgDialog = new OpenFileDialog { Filters = { new FileFilter("AutoCAD Drawings", new string[] { "dwg" }) } }; if (selectDwgDialog.ShowDialog(RhinoEtoApp.MainWindow) == DialogResult.Ok) { var options = new FileReadOptions { ImportMode = true }; if (!RhinoDoc.ReadFile(selectDwgDialog.FileName, options)) { return(Result.Failure); } ZoomNow.ZoomRhinoDoc(); AllLayerOn(); } Layer[] building = GetMultiLayerDialog("选取建筑外轮廓所在图层"); if (building == null) { return(Result.Failure); } return(Result.Success); }
public void Browse_Click(object sender, EventArgs e) { var dialog = new OpenFileDialog(); if (dialog.ShowDialog(this) == DialogResult.Ok) { textArea.Append($"[{DateTime.Now}] Arquivo selecionado: {dialog.FileName}"); viewModel.Path = dialog.FileName; } }
Control OpenFile () { var button = new Button { Text = "Open File" }; button.Click += delegate { var dialog = new OpenFileDialog (); var result = dialog.ShowDialog (this.ParentWindow); if (result == DialogResult.Ok) { Log.Write (dialog, "Result: {0}, FileName: {1}", result, dialog.FileName); } else Log.Write (dialog, "Result: {0}", result); }; return button; }
/// <summary> /// /// </summary> /// <returns></returns> public Task<string> GetImageKey() { var dlg = new OpenFileDialog(); dlg.Filters.Add(new FileDialogFilter("All", ".*")); var result = dlg.ShowDialog(this); if (result == DialogResult.Ok) { var path = dlg.FileName; var bytes = System.IO.File.ReadAllBytes(path); var key = _context.Editor.Project.AddImageFromFile(path, bytes); return Task.Run(() => key); } return null; }
Control OpenFileWithFilters () { var button = new Button { Text = "Open File With Filters" }; button.Click += delegate { var dialog = new OpenFileDialog (); dialog.Filters = GetFilters ("All Formats"); var result = dialog.ShowDialog (this.ParentWindow); if (result == DialogResult.Ok) { Log.Write (dialog, "Result: {0}, CurrentFilter: {1}, FileName: {2}", result, dialog.CurrentFilter, dialog.FileName); } else Log.Write (dialog, "Result: {0}", result); }; return button; }
void _buttonInstallFrom_Click(object sender, EventArgs e) { var openFileDialog = new OpenFileDialog { Title = "Select Altman Plugin To Install", Filters = {new FileDialogFilter("Altman Plugin Zip File", ".zip")} }; if (openFileDialog.ShowDialog(Application.Instance.MainForm) == DialogResult.Ok) { var srcfiles = openFileDialog.Filenames; var install = new InstallDialog(_host); install.InstallPluginCompletedToDo += new EventHandler(install_InstallPluginCompletedToDo); install.Show(); install.InstallOffline(srcfiles); } }
void OnButtonSelectPathClick(object sender, EventArgs e) { if (Filters != null) { // Handle file selection using (var dialog = new OpenFileDialog()) { foreach (var filter in Filters) { dialog.Filters.Add(filter); } if (TextBoxPath.Text.Length != 0) { var fileInfo = new FileInfo(TextBoxPath.Text); if (fileInfo.Exists) { Debug.Assert(fileInfo.DirectoryName != null, "fileInfo.DirectoryName != null"); dialog.Directory = new Uri(fileInfo.DirectoryName); } else { dialog.Directory = new Uri(Utilities.ApplicationBaseDirectory); } } if (dialog.ShowDialog(this) == DialogResult.Ok) { TextBoxPath.Text = Utilities.GetRelativePath(dialog.FileName); } } } else { // Handle directory selection using (var dialog = new SelectFolderDialog()) { if (TextBoxPath.Text.Length != 0) { var directory = Utilities.GetAbsolutePath(TextBoxPath.Text); if (Directory.Exists(directory)) dialog.Directory = directory; } if (dialog.ShowDialog(this) == DialogResult.Ok) { TextBoxPath.Text = Utilities.GetRelativePath(dialog.Directory); } } } TextBoxPath.SelectAll(); TextBoxPath.Focus(); }
void ItemUpload_Executed(object sender, EventArgs e) { var openFileDialog = new OpenFileDialog { Title = "Select File To Upload", Filters = { new FileDialogFilter("All Files", ".*"), new FileDialogFilter("Script Files", ".asp", ".aspx", ".php", ".jsp"), new FileDialogFilter("Program", ".exe", ".bat") } }; if (openFileDialog.ShowDialog(_status.FileGridView) == DialogResult.Ok) { string srcfile = openFileDialog.FileName; string currentDirPath = _status.CurrentDirPath; string fileName = Path.GetFileName(srcfile); string targetFilePath = Path.Combine(currentDirPath, fileName); UploadFile(srcfile, targetFilePath); } }
public static IEnumerable<OsmSharp.Osm.Data.Memory.MemoryDataSource> OpenFiles(Control parent, String title = "Open Files") { var filters = new[] { new FileDialogFilter("Open Street Map (*.osm, *.pbf)", ".osm", ".pbf") }; var dataSources = new List<OsmSharp.Osm.Data.Memory.MemoryDataSource>(); using (OpenFileDialog ofd = new OpenFileDialog() { CheckFileExists = true, MultiSelect = true, Title = title, Filters = filters }) { DialogResult result = ofd.ShowDialog(parent); if (result == DialogResult.Ok) { foreach (String fileName in ofd.Filenames) { dataSources.Add(OpenFileOsm(new FileInfo(fileName))); } } } return dataSources; }
private void BrowseForFile() { var dialog = new OpenFileDialog(); if (dialog.ShowDialog(this) == DialogResult.Ok) _fileSelectTextBox.Text = dialog.FileName; }
Control OpenFile() { var button = new Button { Text = "Open File" }; button.Click += delegate { var dialog = new OpenFileDialog(); SetAttributes(dialog); var result = dialog.ShowDialog(ParentWindow); if (result == DialogResult.Ok) { Log.Write(dialog, "Result: {0}, FileName: {1}\nFiles: {2}", result, dialog.FileName, string.Join(", ", dialog.Filenames)); } else Log.Write(dialog, "Result: {0}", result); }; return button; }
public IEnumerable<string> OpenFiles() { using (var fileDialog = new OpenFileDialog()) return fileDialog.ShowDialog(Owner) == DialogResult.Ok ? fileDialog.Filenames : null; }
public static void ImportCaidaoShell() { if (!Eto.EtoEnvironment.Platform.IsWindows) { MessageBox.Show("Sorry, only supports windows."); return; } var openFileDialog = new OpenFileDialog { Title = "Select Caidao Databse To Import", Filters = {new FileDialogFilter("Caidao Databses", ".mdb")} }; if (openFileDialog.ShowDialog(Application.Instance.MainForm) == DialogResult.Ok) { var srcfile = openFileDialog.FileName; //var pwd = "密" + (char) 13 + (char) 9 + (char) 10 + "码" + (char) 2; var pwd = Encoding.GetEncoding(936).GetString(new byte[] { 0xc3, 0xdc, 0x0d, 0x09, 0x0a, 0xc2, 0xeb, 0x02 }); var connString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source={0};" + "Mode=Share Deny Read|Share Deny Write;Persist Security Info=False;" + "Jet OLEDB:Database Password=\"{1}\"", srcfile, pwd); AccessHelper.ConnString = connString; try { var sites = GetCaiDaoSite(); var shellList = new List<Shell>(); foreach (DataRow row in sites.Rows) { shellList.Add(ConvertCaiDaoDataRowToShell(row)); } foreach (var shell in shellList) { ShellManager.Insert(shell); } if (shellList.Count > 0) { MessageBox.Show(string.Format("Imported {0} Shell(s)", shellList.Count)); MessageBox.Show( StrRes.GetString("StrImportCaidaoShellInfo", "Although the data of caidao be imported successfully, but it's scriptType and Config are not compatible with altman, you may still need to modify some data manually.")); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public static void ImportAltmanShellFromXml() { var openFileDialog = new OpenFileDialog { Title = "Select Altman Xml To Import", Filters = {new FileDialogFilter("Altman Xml", ".xml")} }; if (openFileDialog.ShowDialog(Application.Instance.MainForm) == DialogResult.Ok) { var srcfile = openFileDialog.FileName; try { var xmlString = GetAltmanXml(srcfile); var datas = ConvertXmlToDataTable(xmlString); var shellList = new List<Shell>(); foreach (DataRow row in datas.Rows) { shellList.Add(ConvertAltmanDataRowToShell(row)); } foreach (var shell in shellList) { ShellManager.Insert(shell); } if (shellList.Count > 0) { MessageBox.Show(string.Format("Imported {0} Shell(s)", shellList.Count)); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void ImportCsv(ref Collection <UserStringItem> collection) { //Import a csv file try { #region ETO Open File Dialog var fd = new Eto.Forms.OpenFileDialog { MultiSelect = false, Title = m_dialog_import_title }; //Add the option to read from 3dm's if we're a Document Text panel and not an Object Attribute Panel var rhino_file_filter = new FileFilter(m_rhino_str, m_3_dm); if (IsDocumentText) { fd.Filters.Add(rhino_file_filter); } //Add the other file type filters fd.Filters.Add(new FileFilter(m_csvstr, m_csv)); fd.Filters.Add(new FileFilter(m_txtstr, m_txt)); fd.CurrentFilter = fd.Filters[0]; var result = fd.ShowDialog(RhinoEtoApp.MainWindow); if (result != DialogResult.Ok) { return; } var file_name = fd.FileName; if (IsFileLocked(new FileInfo(file_name))) { Dialogs.ShowMessage(m_file_locked_message, m_file_error_message_title, ShowMessageButton.OK, ShowMessageIcon.Error); return; } #endregion //Lets open up a 3dm if we're in doc mode and need a 3dm if (fd.CurrentFilter == rhino_file_filter) { Import3Dm(file_name); return; } //Grab some csv either from csv file or txt file #region Stream Reader to parse opened file using (var reader = new StreamReader(file_name)) { string line; var csv_parser = new Regex(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))"); while ((line = reader.ReadLine()) != null) { var x = csv_parser.Split(line); if (!x.Any()) { continue; } var entry = new UserStringItem { Key = CreateUniqueKey(x[0], true, ref collection), Value = x[1] }; collection.Add(entry); } } #endregion } catch (Exception ex) { Rhino.Runtime.HostUtils.DebugString("Exception caught during Options - User Text - CSV Import"); Rhino.Runtime.HostUtils.ExceptionReport(ex); } }
/// <summary> /// Display an open file dialog and returns the selected file name, null otherwise. /// </summary> /// <param name="windowTitle">Window title.</param> /// <param name="extensions">File extension mask.</param> /// <returns>Selected file name, null otherwise</returns> public static string OpenFile(string windowTitle = "Open file", params string[] extensions) { string fileName = null; using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Title = windowTitle; dialog.CheckFileExists = true; dialog.Filters.Add(new FileDialogFilter("(Default)", extensions)); var result = dialog.ShowDialog(null); if (result == DialogResult.Ok) fileName = dialog.FileName; } return fileName; }
Control OpenFileWithFilters() { var button = new Button { Text = "Open File With Filters" }; button.Click += delegate { var dialog = new OpenFileDialog { Filters = { new FileDialogFilter("All Formats", "png", "jpg", "jpeg", "gif", "tiff"), "PNG Files|png", new FileDialogFilter("JPeg Files", "jpg", "jpeg"), new FileDialogFilter("GIF Files", "gif"), new FileDialogFilter("TIFF Files", "tiff"), } }; SetAttributes(dialog); var result = dialog.ShowDialog(ParentWindow); if (result == DialogResult.Ok) { Log.Write(dialog, "Result: {0}, CurrentFilter: {1}, FileName: {2}\nFiles: {3}", result, dialog.CurrentFilter, dialog.FileName, string.Join(", ", dialog.Filenames)); } else Log.Write(dialog, "Result: {0}", result); }; return button; }
/// <summary> /// /// </summary> private void InitializeMenu() { #region File var newCommand = new Command() { MenuText = "&New", Shortcut = Application.Instance.CommonModifier | Keys.N }; newCommand.Executed += (s, e) => { _context.Commands.NewCommand.Execute(null); if (_context.Invalidate != null) { _context.Invalidate(); } }; var openCommand = new Command() { MenuText = "&Open...", Shortcut = Application.Instance.CommonModifier | Keys.O }; openCommand.Executed += (s, e) => { var dlg = new OpenFileDialog(); dlg.Filters.Add(new FileDialogFilter("Project", ".project")); dlg.Filters.Add(new FileDialogFilter("All", ".*")); var result = dlg.ShowDialog(this); if (result == DialogResult.Ok) { _context.Open(dlg.FileName); if (_context.Invalidate != null) { _context.Invalidate(); } } }; var saveAsCommand = new Command() { MenuText = "Save &As...", Shortcut = Application.Instance.CommonModifier | Keys.S }; saveAsCommand.Executed += (s, e) => { var dlg = new SaveFileDialog(); dlg.Filters.Add(new FileDialogFilter("Project", ".project")); dlg.Filters.Add(new FileDialogFilter("All", ".*")); dlg.FileName = _context.Editor.Project.Name; var result = dlg.ShowDialog(this); if (result == DialogResult.Ok) { _context.Save(dlg.FileName); } }; var exportCommand = new Command() { MenuText = "&Export...", Shortcut = Application.Instance.CommonModifier | Keys.E }; exportCommand.Executed += (s, e) => { var dlg = new SaveFileDialog(); dlg.Filters.Add(new FileDialogFilter("Pdf", ".pdf")); dlg.Filters.Add(new FileDialogFilter("Dxf", ".dxf")); dlg.Filters.Add(new FileDialogFilter("All", ".*")); dlg.FileName = _context.Editor.Project.Name; var result = dlg.ShowDialog(this); if (result == DialogResult.Ok) { string path = dlg.FileName; int filterIndex = dlg.CurrentFilterIndex; switch (filterIndex) { case 0: _context.ExportAsPdf(path, _context.Editor.Project); Process.Start(path); break; case 1: _context.ExportAsDxf(path); Process.Start(path); break; default: break; } } }; var exitCommand = new Command() { MenuText = "E&xit", Shortcut = Application.Instance.AlternateModifier | Keys.F4 }; exitCommand.Executed += (s, e) => { Application.Instance.Quit(); }; #endregion #region Tool var noneTool = new Command() { MenuText = "&None", Shortcut = Keys.N }; noneTool.Executed += (s, e) => { _context.Commands.ToolNoneCommand.Execute(null); }; var selectionTool = new Command() { MenuText = "&Selection", Shortcut = Keys.S }; selectionTool.Executed += (s, e) => { _context.Commands.ToolSelectionCommand.Execute(null); }; var pointTool = new Command() { MenuText = "&Point", Shortcut = Keys.P }; pointTool.Executed += (s, e) => { _context.Commands.ToolPointCommand.Execute(null); }; var lineTool = new Command() { MenuText = "&Line", Shortcut = Keys.L }; lineTool.Executed += (s, e) => { _context.Commands.ToolLineCommand.Execute(null); }; var arcTool = new Command() { MenuText = "&Arc", Shortcut = Keys.A }; arcTool.Executed += (s, e) => { _context.Commands.ToolArcCommand.Execute(null); }; var bezierTool = new Command() { MenuText = "&Bezier", Shortcut = Keys.B }; bezierTool.Executed += (s, e) => { _context.Commands.ToolBezierCommand.Execute(null); }; var qbezierTool = new Command() { MenuText = "&QBezier", Shortcut = Keys.Q }; qbezierTool.Executed += (s, e) => { _context.Commands.ToolQBezierCommand.Execute(null); }; var pathTool = new Command() { MenuText = "Pat&h", Shortcut = Keys.H }; pathTool.Executed += (s, e) => { _context.Commands.ToolPathCommand.Execute(null); }; var rectangleTool = new Command() { MenuText = "&Rectangle", Shortcut = Keys.R }; rectangleTool.Executed += (s, e) => { _context.Commands.ToolRectangleCommand.Execute(null); }; var ellipseTool = new Command() { MenuText = "&Ellipse", Shortcut = Keys.E }; ellipseTool.Executed += (s, e) => { _context.Commands.ToolEllipseCommand.Execute(null); }; var textTool = new Command() { MenuText = "&Text", Shortcut = Keys.T }; textTool.Executed += (s, e) => { _context.Commands.ToolTextCommand.Execute(null); }; var imageTool = new Command() { MenuText = "&Image", Shortcut = Keys.I }; imageTool.Executed += (s, e) => { _context.Commands.ToolImageCommand.Execute(null); }; #endregion #region Edit var undoCommand = new Command() { MenuText = "&Undo", Shortcut = Application.Instance.CommonModifier | Keys.Z }; undoCommand.Executed += (s, e) => { _context.Commands.UndoCommand.Execute(null); }; var redoCommand = new Command() { MenuText = "&Redo", Shortcut = Application.Instance.CommonModifier | Keys.Y }; redoCommand.Executed += (s, e) => { _context.Commands.RedoCommand.Execute(null); }; var cutCommand = new Command() { MenuText = "Cu&t", Shortcut = Application.Instance.CommonModifier | Keys.X }; cutCommand.Executed += (s, e) => { _context.Commands.CutCommand.Execute(null); }; var copyCommand = new Command() { MenuText = "&Copy", Shortcut = Application.Instance.CommonModifier | Keys.C }; copyCommand.Executed += (s, e) => { _context.Commands.CopyCommand.Execute(null); }; var pasteCommand = new Command() { MenuText = "&Paste", Shortcut = Application.Instance.CommonModifier | Keys.V }; pasteCommand.Executed += (s, e) => { _context.Commands.PasteCommand.Execute(null); }; var deleteCommand = new Command() { MenuText = "&Delete", Shortcut = Keys.Delete }; deleteCommand.Executed += (s, e) => { _context.Commands.DeleteCommand.Execute(null); }; var selectAllCommand = new Command() { MenuText = "Select &All", Shortcut = Application.Instance.CommonModifier | Keys.A }; selectAllCommand.Executed += (s, e) => { _context.Commands.SelectAllCommand.Execute(null); }; var deSelectAllCommand = new Command() { MenuText = "De&select All", Shortcut = Keys.Escape }; deSelectAllCommand.Executed += (s, e) => { _context.Commands.DeselectAllCommand.Execute(null); }; var clearAllCommand = new Command() { MenuText = "Cl&ear All" }; clearAllCommand.Executed += (s, e) => { _context.Commands.ClearAllCommand.Execute(null); }; var groupCommand = new Command() { MenuText = "&Group", Shortcut = Application.Instance.CommonModifier | Keys.G }; groupCommand.Executed += (s, e) => { _context.Commands.GroupCommand.Execute(null); }; var ungroupCommand = new Command() { MenuText = "U&ngroup", Shortcut = Application.Instance.CommonModifier | Keys.U }; ungroupCommand.Executed += (s, e) => { _context.Commands.UngroupCommand.Execute(null); }; #endregion #region Menu var fileMenu = new ButtonMenuItem() { Text = "&File", Items = { newCommand, new SeparatorMenuItem(), openCommand, new SeparatorMenuItem(), saveAsCommand, new SeparatorMenuItem(), exportCommand } }; var editMenu = new ButtonMenuItem() { Text = "&Edit", Items = { undoCommand, redoCommand, new SeparatorMenuItem(), cutCommand, copyCommand, pasteCommand, deleteCommand, new SeparatorMenuItem(), selectAllCommand, deSelectAllCommand, new SeparatorMenuItem(), clearAllCommand, new SeparatorMenuItem(), groupCommand, ungroupCommand } }; var toolMenu = new ButtonMenuItem() { Text = "&Tool", Items = { noneTool, new SeparatorMenuItem(), selectionTool, new SeparatorMenuItem(), pointTool, new SeparatorMenuItem(), lineTool, arcTool, bezierTool, qbezierTool, new SeparatorMenuItem(), pathTool, new SeparatorMenuItem(), rectangleTool, ellipseTool, new SeparatorMenuItem(), textTool, new SeparatorMenuItem(), imageTool } }; var aboutCommand = new Command() { MenuText = "&About..." }; aboutCommand.Executed += (s, e) => { MessageBox.Show(this, Platform.ID); }; Menu = new MenuBar { Items = { fileMenu, editMenu, toolMenu }, QuitItem = exitCommand, AboutItem = aboutCommand }; #endregion }