ToolDialog.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.IO;
  7. using Ips.Library.Basic;
  8. namespace Ips.Library.DxpLib
  9. {
  10. public class ToolDialog
  11. {
  12. public static string OpenFile(string fileName, string title, string initPath = null, string filter = null, bool mutiSelect = false)
  13. {
  14. OpenFileDialog dlg = new OpenFileDialog();
  15. dlg.InitialDirectory = initPath;
  16. dlg.Title = title;
  17. dlg.Filter = filter;
  18. dlg.FileName = fileName;
  19. dlg.Multiselect = mutiSelect;
  20. string result = null;
  21. if (dlg.ShowDialog() == DialogResult.OK)
  22. {
  23. if(mutiSelect)
  24. {
  25. result = dlg.FileNames.JoinAsString(";");
  26. }
  27. else
  28. {
  29. result = dlg.FileName;
  30. }
  31. }
  32. return result;
  33. }
  34. public static string SaveFile(string fileName, string title, string initPath = null, string filter = null)
  35. {
  36. SaveFileDialog dlg = new SaveFileDialog();
  37. dlg.InitialDirectory = initPath;
  38. dlg.Title = title;
  39. dlg.Filter = filter;
  40. dlg.AddExtension = true;
  41. dlg.FileName = fileName;
  42. string result = null;
  43. if (dlg.ShowDialog() == DialogResult.OK)
  44. {
  45. result = dlg.FileName;
  46. }
  47. return result;
  48. }
  49. public static string OpenFolder(string title, bool showNewFolder = true, string initPath = null)
  50. {
  51. FolderBrowserDialog dlg = new FolderBrowserDialog();
  52. dlg.SelectedPath = initPath;
  53. dlg.Description = title;
  54. dlg.ShowNewFolderButton = showNewFolder;
  55. string result = null;
  56. if (dlg.ShowDialog() == DialogResult.OK)
  57. {
  58. result = dlg.SelectedPath;
  59. }
  60. return result;
  61. }
  62. }
  63. }