0

I have an application where I pass data through the Drag & Drop event from Form A to Form B like so:

// FormA.cs
private void g_SelectionDrag(object sender, CancelEventArgs e)
{
   string path = Path.ChangeExtension(Path.Combine(Path.GetTempFilePath(), Guid.NewGuid().ToString()), ".txt");
   DataObject dobj = new DataObject();
   dobj.SetData(DataFormats.FileDrop, new string[] { path });
   
   // only possibility?
   // dobj.SetData("MyFormat", new object[2] { this, path });

   g.DoDragDrop(dobj, DragDropEffects.Copy);
}

// FormB.cs
void c_DragDrop(object sender, DragEventArgs e)
{
   if (e.Data.GetDataPresent(DataFormats.FileDrop, true) && (e.Data.GetData(DataFormats.FileDrop, true) != null))
   {
      String[] SelectedFiles = (String[])e.Data.GetData(DataFormats.FileDrop);
      // do things with the file
   }
}  

Is there a way to receive the sender from the event (this should be FormA) inside FormB? The sender parameter in the DragDrop-event of FormB is only the control receiving the drop-action located in FormB and not the initiator of the drag-event.

Is the only possibilty to pass this with the DataObject.SetData()-function in FormA and include the file-path additionaly or can I receive the source somewhere else?

2
  • 1
    is Control.Parent what you are looking for? Commented Jul 1 at 1:33
  • In FormB my receiver-function is c_DragDrop(). Control c is placed in FormB, so its Parent or FindForm() is FormB. Commented Jul 1 at 6:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.