Click here to Skip to main content
15,885,842 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo,
I m developing a windows application where i am iplemeneting small Drag and Drop function to my windows form
Here is the scenarios
--I got windows Form with Text boxes
-Now i want to Drag something from Desktop say text or filename or folder
and Drop in my Testbox
--i set Allow-Drop Property of my TextboxTrue
here is my code
C#
   private void Mainform_Load(object sender, EventArgs e)
     {
         txtbx_def.AllowDrop = true;
         txtbx_def.DragEnter += new DragEventHandler(Def_DragEnter);
         txtbx_def.DragDrop += new DragEventHandler(Def_DragDrop);

     }

private void txtbx_def_DragDrop(object sender, DragEventArgs e)
    {
        txtbx_def.Text = e.Data.GetData(DataFormats.Text).ToString();

    }

    private void txtbx_def_DragEnter(object sender, DragEventArgs e)
    {

        if (e.Data.GetDataPresent(DataFormats.Text))
        {
            e.Effect = DragDropEffects.Copy;

        }
        else
        {
            e.Effect = DragDropEffects.None;
        }

    }

But even the event is not Trigerred why????
It is not working
Posted
Updated 25-Nov-14 0:20am
v2
Comments
BillWoodruff 25-Nov-14 9:30am    
Is the drag-drop of Text working ? Any other type of drag-drop working ?

The chances are that one of the events is firing: the DragEnter event.
But what gets dragged from the desktop is not text - it's files. So try this:
C#
private void textBox1_DragEnter(object sender, DragEventArgs e)
    {
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
        e.Effect = DragDropEffects.Copy;

        }
    else
        {
        e.Effect = DragDropEffects.None;
        }
    }
You should find the DragDrop event gets triggered now.
 
Share this answer
 
tried both seems not working at all unfortunately
 
Share this answer
 
Comments
BillWoodruff 25-Nov-14 9:29am    
Please post feedback to a solution as a comment on that solution, not as a separate solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900