We help IT Professionals succeed at work.

C# Determine Sender control in Drag Drop operation

pr_wainwright
on
Hi,
    How can I determine the name or tag of the control (sender) that initiated (mouse down event) a Drag Drop operation in the DragEnter event of the recipient?

e.g. If an image named 'Image1' is dragged onto a Panel named 'Panel1' in Panel1's DragEnter event how can I get the name (or tag) of Image1?

Thanks
Paul.
Comment
Watch Question

Commented:
Hi,

You can do like this

            private void panel1_DragDrop(object sender, DragEventArgs e) {
                  ((PictureBox)(e.Data.GetData(typeof(PictureBox)))).Tag   // Use tag as you need
            }

            private void pictureBox1_MouseDown(object sender, MouseEventArgs e) {
                  DoDragDrop((PictureBox)sender, DragDropEffects.Link);
            }

/peter

Commented:
try: (sender as Control).Tag,....

Author

Commented:
Thanks for the help.
Paul.