PasteDragDrop firing on DragEnter?

SyntaxEditor for Windows Forms Forum

Posted 14 years ago by Jason Whitted - Owner, Etalisoft, LLC
Avatar
I'm trying to load a file when it is dropped onto the editor; however, I'm running into a problem where the PasteDragDrop event is firing on DragEnter instead of DragDrop.

Below is a small application which illistrates the problem.
using System;
using System.Windows.Forms;
using ActiproSoftware.SyntaxEditor;
using System.Diagnostics;

public partial class Form1 : Form
{
    private SyntaxEditor editor;

    public Form1()
    {
        editor = new SyntaxEditor();
        editor.Dock = DockStyle.Fill;
        this.Controls.Add(editor);

        editor.AllowDrop = true;
        editor.PasteDragDrop += new PasteDragDropEventHandler(editor_PasteDragDrop);
    }

    private void editor_PasteDragDrop(object sender, PasteDragDropEventArgs e)
    {
        if (e.DataObject.GetDataPresent(DataFormats.FileDrop))
        {
            string[] files = e.DataObject.GetData(DataFormats.FileDrop) as string[];
            if (files == null || files.Length == 0) return;
            Debug.WriteLine(String.Format("{0:hh:mm:ss.fff} editor_PasteDragDrop --> LoadFile", DateTime.Now));
            editor.Document.LoadFile(files[0]);
        }
    }
}

Comments (5)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Actually that's by design. The reason is so that we know whether to display a drop-allowed cursor or not. Essentially you can set e.Text to any non-null value to allow the drop, or a null value to show a cursor that indicates it can't be dropped.


Actipro Software Support

Posted 14 years ago by Jason Whitted - Owner, Etalisoft, LLC
Avatar
OK? So how can I determine when the file is actually dropped so I can load the file instead of it loading the file on DragEnter?
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
There is an event args parameter that indicates what is calling the event (DragEnter, DragDrop, etc.). Do it only in DragDrop.


Actipro Software Support

Posted 14 years ago by Jason Whitted - Owner, Etalisoft, LLC
Avatar
Aha! PasteDragDropEventArgs.Source was there all along. Thanks a lot for the help.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
No problem!


Actipro Software Support

The latest build of this product (v2018.1 build 0342) was released 11 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.