drop files / folders:
first Preparation:
"AllowDrop" property set and log 2 Events:
1: public MainForm ()
2: {
3: InitializeComponent ();
4: this textboxDir.AllowDrop. = true;
5: this textboxDir.DragOver + = new DragEventHandler (textboxDir_DragOver);
6. this textboxDir.DragDrop + = new DragEventHandler (textboxDir_DragDrop). ;
7:}
second Drag Over Event:
check data format and DragDropEffects contact: (object sender
, DragEventArgs e)
void
textboxDir_DragOver 2::
a {
3: if (e.Data.GetDataPresent(DataFormats.FileDrop))
4: {
5: e.Effect = DragDropEffects.Move;
6: }
7: }
3. Drag-Drop-Event:
Drop auswerten:
1: void textboxDir_DragDrop( object sender, DragEventArgs e)
2: {
3: if (e.Effect == DragDropEffects.Move) // if move
4: {
5: if (e.Data.GetDataPresent (DataFormats.FileDrop)) / / if FileDrop
6: {
7: string [] dirName = ( string []) e.Data.GetData (DataFormats.FileDrop);
8: if (dirNames.Length.Equals (1)) / / if just one file
9: {
10: if (MSUtils.FileUtil.dirExists (dirname [0]))
11: {.
12: this textboxDir.Text = dirName [0];
13:
} 14:}
15:}
16:
} 17:}
0 comments:
Post a Comment