Drag and drop

  • Thread starter Thread starter Thorpe
  • Start date Start date
T

Thorpe

I am currentl writting an c# application but I need a few pointers.

I want to allow a user to drag an image from the windows desktop to my
application. I know this is possible with c++ but can this be done in c#. I
have looked into AllowDrop and dragevents etc but this only allows the
application to drag things from with in its self

thanks in advance
 
I am currentl writting an c# application but I need a few pointers.

I want to allow a user to drag an image from the windows desktop to my
application. I know this is possible with c++ but can this be done in c#. I
have looked into AllowDrop and dragevents etc but this only allows the
application to drag things from with in its self

thanks in advance

Have a look at the drop event for the control that the files are being
dropped on, for a ListView it would be:

private void lvRIGHT_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e)

The parameter DragEventArgs 'e' contains the data you will need and
you can get at it like this (it may be in other formats depending on
its source):

if (e.Data.GetDataPresent(DataFormats.FileDrop))
string[] strFiles = (string[])e.Data.GetData(DataFormats.FileDrop);

This gives you an array of (fully qualified) file names that are being
dropped. You can then copy/move/create shortcuts etc. I tend to use
the API for events like that but you could also use native functions.
 
Back
Top