"Jeff Williams" <je*******************@hardsoft.com.auwrote in message
news:13*************@corp.supernews.com...
>I have several picture boxes on a form. I want to be able to drag pictures
to this picture box. On the Drop how can I tell which picture box I am
dropping the picture on. Te picture Box control name or control text would
suit my needs.
Are you using a single DragDrop event for all your pictureboxes? In that
case, the first argument, "sender", is a reference to the control that
triggered the event, which is the picturebox in which you are dropping the
picture. Since it is of type Object, you will have to cast it into
PictureBox.
private void MyPictureBoxes_DragDrop(object sender, DragEventArgs e)
{
PictureBox dropTarget = sender as PictureBox;
if (dropTarget==null) return; //Should never happen
if (e.Data.GetDataPresent(typeof(Image))) {
Image item = (Image)e.Data.GetData(typeof(Image));
if (e.Effect == DragDropEffects.Copy ||
e.Effect == DragDropEffects.Move) {
dropTarget.Image = item;
}
}
}