Drag & Drop how to in Windows Application
-
Hi, I am creating a simple application for drag & drop. I am using Windows 10 OS, Visual Studio 2015 & creating windows application using c#. I have added pannel on the form. AllowDrop is true for the panel. I have added 3 events from event windows for Panel : private void panel1_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.All; } private void panel1_DragOver(object sender, DragEventArgs e) { e.Effect = DragDropEffects.All; } private void panel1_DragDrop(object sender, DragEventArgs e) { } But it is not allowing me to drop files here. Please let me know what is wrong with the code.
Gaurav Goyal
-
Hi, I am creating a simple application for drag & drop. I am using Windows 10 OS, Visual Studio 2015 & creating windows application using c#. I have added pannel on the form. AllowDrop is true for the panel. I have added 3 events from event windows for Panel : private void panel1_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.All; } private void panel1_DragOver(object sender, DragEventArgs e) { e.Effect = DragDropEffects.All; } private void panel1_DragDrop(object sender, DragEventArgs e) { } But it is not allowing me to drop files here. Please let me know what is wrong with the code.
Gaurav Goyal
I just duplicated what you did, and it works fine for me - a breakpoint on the panel DragDrop event handler gets hit, and I appear to have data. Check what you are dragging, and where you are dragging it from, as well as checking that the events are hooked to the handlers.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
Hi, I am creating a simple application for drag & drop. I am using Windows 10 OS, Visual Studio 2015 & creating windows application using c#. I have added pannel on the form. AllowDrop is true for the panel. I have added 3 events from event windows for Panel : private void panel1_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.All; } private void panel1_DragOver(object sender, DragEventArgs e) { e.Effect = DragDropEffects.All; } private void panel1_DragDrop(object sender, DragEventArgs e) { } But it is not allowing me to drop files here. Please let me know what is wrong with the code.
Gaurav Goyal
OK, what did you expect to happen? That code works perfectly fine, but since your DragDrop event handler is empty, nothing is going to happen when you release the mouse. YOU have to supply the code to process whatever data is being dropped on the control. The Panel control has no clue what you want to happen with these files being dropped.
System.ItDidntWorkException: Something didn't work as expected. C# - How to debug code[^]. Seriously, go read these articles.
Dave Kreskowiak -
OK, what did you expect to happen? That code works perfectly fine, but since your DragDrop event handler is empty, nothing is going to happen when you release the mouse. YOU have to supply the code to process whatever data is being dropped on the control. The Panel control has no clue what you want to happen with these files being dropped.
System.ItDidntWorkException: Something didn't work as expected. C# - How to debug code[^]. Seriously, go read these articles.
Dave KreskowiakI put some sample code there. but still not working. I am just dragging a text file from windows explorer & dropping here.
Gaurav Goyal
-
I just duplicated what you did, and it works fine for me - a breakpoint on the panel DragDrop event handler gets hit, and I appear to have data. Check what you are dragging, and where you are dragging it from, as well as checking that the events are hooked to the handlers.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
I am just dragging a text file & dropping here.
Gaurav Goyal
-
I put some sample code there. but still not working. I am just dragging a text file from windows explorer & dropping here.
Gaurav Goyal
And that still doesn't explain what you think was going to happen or want to happen. We also can't see the code you put in the Drop event handler. Without being able to see the code, it's IMPOSSIBLE to tell you what you're doing wrong and/or how your expectations need to change.
System.ItDidntWorkException: Something didn't work as expected. C# - How to debug code[^]. Seriously, go read these articles.
Dave Kreskowiak -
I am just dragging a text file & dropping here.
Gaurav Goyal
And what happened? What code did you use to get the file that was dropped, and what happened when you tried - remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
Hi, I am creating a simple application for drag & drop. I am using Windows 10 OS, Visual Studio 2015 & creating windows application using c#. I have added pannel on the form. AllowDrop is true for the panel. I have added 3 events from event windows for Panel : private void panel1_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.All; } private void panel1_DragOver(object sender, DragEventArgs e) { e.Effect = DragDropEffects.All; } private void panel1_DragDrop(object sender, DragEventArgs e) { } But it is not allowing me to drop files here. Please let me know what is wrong with the code.
Gaurav Goyal