943,568 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 7299
  • C# RSS
Jan 6th, 2009
0

Drag and drop from windows forms to desktop and windows explorer

Expand Post »
Hello there, I've been having a hard time lately with implementing the drag and drop functionality outside the windows forms. I have no problem doing drag and drop within and between windows forms and from the desktop to the windows form. I have created an application where you can drag and drop any item on it. My problem is, I do not know how to implement the reverse of my application, to drag and drop from my app to the desktop or any destination outside my form. Any advise and ideas I will gratefully accept. Thank you.
Similar Threads
Reputation Points: 7
Solved Threads: 2
Junior Poster
murderotica is offline Offline
171 posts
since Aug 2008
Jan 6th, 2009
0

Re: Drag and drop from windows forms to desktop and windows explorer

google is your friend - a bit of resarch to find out what the desktop wants and will accept dropped onto it should help.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Jan 6th, 2009
0

Re: Drag and drop from windows forms to desktop and windows explorer

I found a resource and tried it but it seems that when I try to drop my file to the desktop, nothing happens. I can drag it already but it cannot drop the file. Here's what I did:

C# Syntax (Toggle Plain Text)
  1. private void listview_ItemDrag(object sender, ItemDragEventArgs e){
  2. DataObject object = new DataObject()
  3. string f = listview.SelectedItems[0].Text;
  4. object.SetData(DataFormats.FileDrop, f);
  5. DoDragDrop(object, DragDropEffects.All);
  6. }

It can drag already but cannot drop. What do you think is the problem?
Last edited by murderotica; Jan 6th, 2009 at 5:17 am.
Reputation Points: 7
Solved Threads: 2
Junior Poster
murderotica is offline Offline
171 posts
since Aug 2008
Jan 7th, 2009
0

Re: Drag and drop from windows forms to desktop and windows explorer

Maybe I need a RegisterDragDrop() function but it seems its not available in C#?
Reputation Points: 7
Solved Threads: 2
Junior Poster
murderotica is offline Offline
171 posts
since Aug 2008
Jun 20th, 2009
0

Re: Drag and drop from windows forms to desktop and windows explorer

hi
i want to implement that u have implemented..drag and drop anywhere outside the form but using mouse events only no drag and drop events....
can u help me regarding this...........

thanks in advance
Reputation Points: 10
Solved Threads: 0
Newbie Poster
exploree_123 is offline Offline
1 posts
since Jun 2009
Jun 20th, 2009
0

Re: Drag and drop from windows forms to desktop and windows explorer

hmmm... the only way I can think of to do that one is that to play with the location of the object that is being dragged.. so let's say while you
're dragging your object the X and Y Coordinates is updated.. now when you release the mouse, you try to check the X and Y coordinates of the object and if it is outside the bounds of the FORM, then you assume that the object has been dragged out of the form and perform the necessary event...

i haven't done this yet but give it a try and tell me if it worked
Reputation Points: 7
Solved Threads: 1
Junior Poster in Training
it2051229 is offline Offline
82 posts
since May 2007
Jun 20th, 2009
-1

Re: Drag and drop from windows forms to desktop and windows explorer

http://social.msdn.microsoft.com/for...-0421a6378b47/

This information seems hand, for files, but just for sake of working code, there is a codeproject example that has a demo app with source code of how to drag a url shortcut to the desktop from you application found here

http://www.codeproject.com/KB/cs/dra...tshortcut.aspx

I wish I had more, I have been putting off working this out for a feature in an app I'm working on myself.

best of luck.
Reputation Points: 442
Solved Threads: 89
Master Poster
Diamonddrake is offline Offline
721 posts
since Mar 2008
Mar 15th, 2010
-1
Re: Drag and drop from windows forms to desktop and windows explorer
http://social.msdn.microsoft.com/for...-0421a6378b47/

This information seems hand, for files, but just for sake of working code, there is a codeproject example that has a demo app with source code of how to drag a url shortcut to the desktop from you application found here

http://www.codeproject.com/KB/cs/dra...tshortcut.aspx

I wish I had more, I have been putting off working this out for a feature in an app I'm working on myself.

best of luck.
Did anybody solve this? It has to be possible because several existing applications have the feature to drag files to Explorer folders. Dragging is enabled but the file isn't moving or copying.

If you don't know the answer or aren't willing to help please don't suggest googling.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
starapple is offline Offline
2 posts
since Feb 2010
Jan 4th, 2011
0
Re: Drag and drop from windows forms to desktop and windows explorer
hey I came across this thread with the same problem. however the solution working for me looks very much the same - at least I can find no real difference. I can select entries from my listview, and drag them onto the desktop, and there it creates a copy. (I do force a copy with the DragDropEffects, but it works also with DragDropEffects.All.)

here is my code:
C# Syntax (Toggle Plain Text)
  1. private void lsvFiles_ItemDrag(object sender, ItemDragEventArgs e)
  2. {
  3. // Proceed with the drag-and-drop, passing the selected items for
  4. string[] filepaths = new string[listview.SelectedItems.Count];
  5. int i = 0;
  6. foreach (ListViewItem item in listview.SelectedItems)
  7. filepaths[i++] = ((FileInfo)item.Tag).FullName;
  8. DataObject data = new DataObject(DataFormats.FileDrop, filepaths);
  9. data.SetData(DataFormats.StringFormat, filepaths);
  10. DoDragDrop(data, DragDropEffects.Copy);
  11. }
Last edited by dbirdz; Jan 4th, 2011 at 12:07 pm. Reason: better legible layout
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dbirdz is offline Offline
1 posts
since Jan 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Text Box Validations
Next Thread in C# Forum Timeline: Matrix Dimensions





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC