Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Drag & Drop how to in Windows Application

Drag & Drop how to in Windows Application

Scheduled Pinned Locked Moved C#
csharpvisual-studiotutorialquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GauravGoyal_5
    wrote on last edited by
    #1

    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

    OriginalGriffO D M 3 Replies Last reply
    0
    • G GauravGoyal_5

      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

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      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 have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      G 1 Reply Last reply
      0
      • G GauravGoyal_5

        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

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        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

        G 1 Reply Last reply
        0
        • D 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 Kreskowiak

          G Offline
          G Offline
          GauravGoyal_5
          wrote on last edited by
          #4

          I put some sample code there. but still not working. I am just dragging a text file from windows explorer & dropping here.

          Gaurav Goyal

          D 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            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!

            G Offline
            G Offline
            GauravGoyal_5
            wrote on last edited by
            #5

            I am just dragging a text file & dropping here.

            Gaurav Goyal

            OriginalGriffO 1 Reply Last reply
            0
            • G GauravGoyal_5

              I put some sample code there. but still not working. I am just dragging a text file from windows explorer & dropping here.

              Gaurav Goyal

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • G GauravGoyal_5

                I am just dragging a text file & dropping here.

                Gaurav Goyal

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #7

                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!

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                1 Reply Last reply
                0
                • G GauravGoyal_5

                  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

                  M Offline
                  M Offline
                  MAIsw
                  wrote on last edited by
                  #8

                  Are you running the application in admin mode? Windows 10 blocks drag&drop for security reasons under circumstances.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups