CraftSynth.ImageEditor – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 #region Using directives
2  
3 using System;
4 using System.Windows.Forms;
5  
6 #endregion
7  
8 namespace DocToolkit
9 {
10 /// <summary>
11 /// DragDropManager class allows to open files dropped from
12 /// Windows Explorer in Windows Form application.
13 ///
14 /// Using:
15 /// 1) Write function which opens file selected from MRU:
16 ///
17 /// private void dragDropManager_FileDroppedEvent(object sender, FileDroppedEventArgs e)
18 /// {
19 /// // open file(s) from e.FileArray:
20 /// // e.FileArray.GetValue(0).ToString() ...
21 /// }
22 ///
23 /// 2) Add member of this class to the parent form:
24 ///
25 /// private DragDropManager dragDropManager;
26 ///
27 /// 3) Create class instance in parent form initialization code:
28 ///
29 /// dragDropManager = new DragDropManager(this);
30 /// dragDropManager.FileDroppedEvent += dragDropManager_FileDroppedEvent;
31 ///
32 /// </summary>
33 public class DragDropManager
34 {
35 private Form frmOwner; // reference to owner form
36  
37 // Event raised when drops file(s) to the form
38 public event FileDroppedEventHandler FileDroppedEvent;
39  
40 public DragDropManager(Form owner)
41 {
42 frmOwner = owner;
43  
44 //// ensure that parent form allows dropping
45 //frmOwner.AllowDrop = true;
46  
47 //// subscribe to parent form's drag-drop events
48 //frmOwner.DragEnter += OnDragEnter;
49 //frmOwner.DragDrop += OnDragDrop;
50 }
51  
52  
53 /// <summary>
54 /// Handle parent form DragEnter event
55 /// </summary>
56 /// <param name="sender"></param>
57 /// <param name="e"></param>
58 private void OnDragEnter(object sender, System.Windows.Forms.DragEventArgs e)
59 {
60 // If file is dragged, show cursor "Drop allowed"
61 if (e.Data.GetDataPresent(DataFormats.FileDrop))
62 e.Effect = DragDropEffects.Copy;
63 else
64 e.Effect = DragDropEffects.None;
65 }
66  
67 /// <summary>
68 /// Handle parent form DragDrop event
69 /// </summary>
70 /// <param name="sender"></param>
71 /// <param name="e"></param>
72 private void OnDragDrop(object sender, System.Windows.Forms.DragEventArgs e)
73 {
74 // When file(s) are dragged from Explorer to the form, IDataObject
75 // contains array of file names. If one file is dragged,
76 // array contains one element.
77 Array a = (Array)e.Data.GetData(DataFormats.FileDrop);
78  
79 if (a != null)
80 {
81 if (FileDroppedEvent != null)
82 {
83 // Raise event asynchronously.
84 // Explorer instance from which file is dropped is not responding
85 // all the time when DragDrop handler is active, so we need to return
86 // immidiately (especially if OpenFiles shows MessageBox).
87  
88 FileDroppedEvent.BeginInvoke(this, new FileDroppedEventArgs(a), null, null);
89  
90 frmOwner.Activate(); // in the case Explorer overlaps parent form
91 }
92 }
93  
94 // NOTE: exception handling is not used here.
95 // Caller responsibility is to handle exceptions
96 // in the function invoked by FileDroppedEvent.
97 }
98 }
99  
100 public delegate void FileDroppedEventHandler(object sender, FileDroppedEventArgs e);
101  
102 public class FileDroppedEventArgs : System.EventArgs
103 {
104 private Array fileArray;
105  
106 public FileDroppedEventArgs(Array array)
107 {
108 this.fileArray = array;
109 }
110  
111 public Array FileArray
112 {
113 get
114 {
115 return fileArray;
116 }
117 }
118 }
119 }
120