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?
Control.Parentwhat you are looking for?FormBmy receiver-function isc_DragDrop(). Controlcis placed inFormB, so itsParentorFindForm()isFormB.