123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- namespace TSZ.DotNetDll.WinForms
- {
- using System;
- using System.IO;
- using System.Windows.Forms;
- using TSZ.DotNetDll;
- public class OpenFileDialogEx : IDisposable
- {
- private bool __Disposed;
- private OpenFileDialog dialog;
- private string flagGuid;
- public OpenFileDialogEx() : this(null)
- {
- }
- public OpenFileDialogEx(string flagGuid)
- {
- this.flagGuid = flagGuid;
- this.dialog = new OpenFileDialog();
- try
- {
- string keyValue = RegistryHelper.GetKeyValue(this.REGISTRYKEYFLAG);
- if (!string.IsNullOrEmpty(keyValue) && Directory.Exists(keyValue))
- {
- this.dialog.InitialDirectory = keyValue;
- }
- }
- catch
- {
- }
- }
- public void Dispose()
- {
- if (!this.__Disposed)
- {
- this.dialog.Dispose();
- this.__Disposed = true;
- }
- }
- public void Reset()
- {
- this.dialog.Reset();
- }
- public DialogResult ShowDialog()
- {
- return this.dialog.ShowDialog();
- }
- public DialogResult ShowDialog(IWin32Window owner)
- {
- return this.dialog.ShowDialog(owner);
- }
- public bool CheckFileExists
- {
- get
- {
- return this.dialog.CheckFileExists;
- }
- set
- {
- this.dialog.CheckFileExists = value;
- }
- }
- public string DefaultExt
- {
- get
- {
- return this.dialog.DefaultExt;
- }
- set
- {
- this.dialog.DefaultExt = value;
- }
- }
- public string FileName
- {
- get
- {
- string fileName = this.dialog.FileName;
- if (File.Exists(fileName))
- {
- string directoryName = Path.GetDirectoryName(fileName);
- if (string.IsNullOrEmpty(directoryName))
- {
- return fileName;
- }
- try
- {
- RegistryHelper.SetKeyValue(this.REGISTRYKEYFLAG, directoryName);
- }
- catch
- {
- }
- }
- return fileName;
- }
- set
- {
- this.dialog.FileName = value;
- }
- }
- public string[] FileNames
- {
- get
- {
- if ((this.dialog.FileNames != null) && (this.dialog.FileNames.Length > 0))
- {
- string path = this.dialog.FileNames[0];
- if (File.Exists(path))
- {
- string directoryName = Path.GetDirectoryName(path);
- if (!string.IsNullOrEmpty(directoryName))
- {
- try
- {
- RegistryHelper.SetKeyValue(this.REGISTRYKEYFLAG, directoryName);
- }
- catch
- {
- }
- }
- }
- }
- return this.dialog.FileNames;
- }
- }
- public string Filter
- {
- get
- {
- return this.dialog.Filter;
- }
- set
- {
- this.dialog.Filter = value;
- }
- }
- public bool Multiselect
- {
- get
- {
- return this.dialog.Multiselect;
- }
- set
- {
- this.dialog.Multiselect = value;
- }
- }
- private string REGISTRYKEYFLAG
- {
- get
- {
- if (string.IsNullOrEmpty(this.flagGuid))
- {
- return "FileBrowserDialogSelectedPath";
- }
- return (@"OpenFilePaths\" + this.flagGuid);
- }
- }
- public object Tag
- {
- get
- {
- return this.dialog.Tag;
- }
- set
- {
- this.dialog.Tag = value;
- }
- }
- public string Title
- {
- get
- {
- return this.dialog.Title;
- }
- set
- {
- this.dialog.Title = value;
- }
- }
- }
- }
|