对比新文件 |
| | |
| | | 锘縰sing System.Windows.Forms; |
| | | |
| | | namespace Gs.DevApp.DevFrm.Sys |
| | | { |
| | | public enum FileType |
| | | { |
| | | Txt, |
| | | Xml, |
| | | Pdf, |
| | | Bin, |
| | | Zip, |
| | | All, |
| | | Img, |
| | | Excel |
| | | } |
| | | |
| | | public class FileSelector |
| | | { |
| | | public static string Title = "Please choose the file:"; |
| | | |
| | | public static string Filter = |
| | | "Text files (*.txt)|*.txt|All files (*.*)|*.*"; |
| | | |
| | | /// <summary> |
| | | /// Get or set the initial directory displayed by the file dialog box. |
| | | /// </summary> |
| | | public static OpenFileDialog OFD = new OpenFileDialog(); |
| | | |
| | | public static SaveFileDialog SFD = new SaveFileDialog(); |
| | | |
| | | public static FileType FileExtension |
| | | { |
| | | set |
| | | { |
| | | switch (value) |
| | | { |
| | | case FileType.Txt: |
| | | Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*"; |
| | | break; |
| | | case FileType.Excel: |
| | | Filter = |
| | | "Text files(*.xls;*.xlsx)|*.xls;*.xlsx|All files(*.*)|*.*"; |
| | | break; |
| | | case FileType.Xml: |
| | | Filter = |
| | | "XML files(*.xml)|*.xml|Config files(*.config)|*.config|All files(*.*)|*.*"; |
| | | break; |
| | | case FileType.Pdf: |
| | | Filter = |
| | | "Pdf files(*.Pdf)|*.Pdf|Pdf form files(*.fdf)|*.fdf|All files(*.*)|*.*"; |
| | | break; |
| | | case FileType.Bin: |
| | | Filter = |
| | | "Binary files(*.bin)|*.bin|Application files(*.exe;*.lib;*.dll)|*.exe;*.lib;*.dll|All files(*.*)|*.*"; |
| | | break; |
| | | case FileType.Zip: |
| | | Filter = |
| | | "Zip files(*.zip;*.rar)|*.zip;*.rar|All files(*.*)|*.*"; |
| | | break; |
| | | case FileType.Img: |
| | | Filter = |
| | | "GIF(*.gif)|*.gif|Jpeg(*.jpg)|*.jpg|Bmp(*.bmp)|*.bmp|Emf(*.emf)|*.emf|Png(*.png)|*.png"; |
| | | break; |
| | | case FileType.All: |
| | | Filter = "All files(*.*)|*.*"; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static string InitialPath |
| | | { |
| | | set |
| | | { |
| | | OFD.InitialDirectory = value; |
| | | SFD.InitialDirectory = value; |
| | | } |
| | | } |
| | | |
| | | public static string BrowseFile() |
| | | { |
| | | OFD.Title = Title; |
| | | OFD.Filter = Filter; |
| | | if (OFD.ShowDialog() == DialogResult.OK) |
| | | return OFD.FileName; |
| | | return null; |
| | | } |
| | | |
| | | public static string BrowseFileForSave() |
| | | { |
| | | SFD.Title = Title; |
| | | SFD.Filter = Filter; |
| | | if (SFD.ShowDialog() == DialogResult.OK) |
| | | return SFD.FileName; |
| | | return null; |
| | | } |
| | | |
| | | public static string BrowseFile(FileType type) |
| | | { |
| | | FileExtension = type; |
| | | return BrowseFile(); |
| | | } |
| | | |
| | | public static string BrowseFile(string filter) |
| | | { |
| | | Filter = filter; |
| | | return BrowseFile(); |
| | | } |
| | | |
| | | public static string BrowseFileForSave(FileType type) |
| | | { |
| | | FileExtension = type; |
| | | return BrowseFileForSave(); |
| | | } |
| | | |
| | | public static string BrowseFileForSave(string filter) |
| | | { |
| | | Filter = filter; |
| | | return BrowseFileForSave(); |
| | | } |
| | | |
| | | public static string BrowseFilePathForSave() |
| | | { |
| | | var fbd = new FolderBrowserDialog(); |
| | | if (fbd.ShowDialog() == DialogResult.OK) |
| | | return fbd.SelectedPath; //鑾峰緱閫夋嫨鐨勬枃浠跺す璺緞 |
| | | return ""; |
| | | } |
| | | } |
| | | } |