简体   繁体   中英

Panel Drag and Drop not working in winForms Application

I am developing a winForm application using c#.NET. On the form i have placed a panel, and i have 2 methods :

    private void panel1_DragDrop(object sender, DragEventArgs e){
    //some code here
    }
    private void panel1_DoubleClick(object sender, EventArgs e){
    //some code here
    }

Whenever i run the program in debug mode(x64), i cannot seem to hit panel1_DragDrop method. I have also tried using a breakpoint , but it is also not being hit. I have put property AllowDrop=true for this panel, but still nothing is happening. What could be the possible reason?

Did you tried DragEnter event :

    private void panel1_DragEnter(object sender, DragEventArgs e)
       {
        if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
       }

    private void panel1_DragDrop(object sender, DragEventArgs e)
      {
        string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
        if (Path.GetExtension(files[0]).ToLower() == ".pdf")//jpg,bmp,docx,....
        {
            //Code
        }
      }

Also please check if your application isn't running as another user privilege like Run as Administrator .
"Run as Administrator" prevents drag and drop working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM