.
1: public class MyOpenFileDialog : CommonDialog
2: { 3: private string _filename;
4: private string _title;
5:
6: [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
7: internal class OpenFileName
8: { 9: internal int structSize;
10: internal IntPtr owner;
11: internal IntPtr instance;
12: internal string filter;
13: internal string customFilter;
14: internal int maxCustFilter;
15: internal int filterIndex;
16: internal string file;
17: internal int maxFile;
18: internal string fileTitle;
19: internal int maxFileTitle;
20: internal string initialDir;
21: internal string title;
22: internal Int16 flags;
23: internal Int16 fileOffset;
24: internal int fileExtension;
25: internal string defExt;
26: internal IntPtr custData;
27: internal IntPtr hook;
28: internal string templateName;
29: }
30:
31: [DllImport("comdlg32.dll", CharSet = CharSet.Auto, SetLastError = true)] 32: internal static extern bool GetOpenFileName ([In, Out] OpenFileName ofn);
33:
34: public override void Reset ()
35: { 36: this._filename = null;
37: this._title = null;
38: //Other reset code here...
39: }
40:
41: protected override bool RunDialog (IntPtr hwndOwner)
42: { 43: OpenFileName ofn = new OpenFileName();
44: ofn.file = new string(' ', 0x2000); 45: ofn.owner = hwndOwner;
46: ofn.instance = Marshal.GetHINSTANCE(typeof(MyOpenFileDialog).Module);
47: ofn.title=_title;
48: ofn.maxFile = 0x2000;
49: ofn.structSize = Marshal.SizeOf(ofn);
50: bool ret = GetOpenFileName(ofn);
51: if(ret)_filename = ofn.file.TrimEnd();
52: return ret;
53: }
54:
55: public string FileName
56: { 57: get { return _filename; } 58: }
59: public string Title
60: { 61: get { return _title; } 62: set { _title = value; } 63: }
64:
65: }