source: Common/Dialogs.cs

Last change on this file was 14, checked in by chronos, 21 months ago
  • Modified: Various improvements.
File size: 1.4 KB
Line 
1using System.IO;
2using System.Windows.Forms;
3
4namespace Common
5{
6 class Dialogs
7 {
8 public const string AnyFile = "Any file";
9
10 public static string OpenFileDialog(string fileName, string fileType, string fileExtension)
11 {
12 OpenFileDialog dlg = new OpenFileDialog { Filter = fileType + @"|*." + fileExtension + @"|" + AnyFile + @"|*.*", DefaultExt = fileExtension };
13 if (!string.IsNullOrEmpty(fileName))
14 {
15 dlg.FileName = Path.GetFileName(fileName);
16 dlg.InitialDirectory = Path.GetDirectoryName(fileName);
17 }
18
19 if (dlg.ShowDialog() == DialogResult.OK)
20 {
21 fileName = dlg.FileName;
22 }
23 return fileName;
24 }
25
26 public static string SaveFileDialog(string fileName, string fileType, string fileExtension)
27 {
28 SaveFileDialog dlg = new SaveFileDialog { Filter = fileType + @"|*." + fileExtension + @"|" + AnyFile + @"|*.*", DefaultExt = fileExtension };
29 if (!string.IsNullOrEmpty(fileName))
30 {
31 dlg.FileName = Path.GetFileName(fileName);
32 dlg.InitialDirectory = Path.GetDirectoryName(fileName);
33 }
34
35 if (dlg.ShowDialog() == DialogResult.OK)
36 {
37 fileName = dlg.FileName;
38 }
39 return fileName;
40 }
41 }
42}
Note: See TracBrowser for help on using the repository browser.