Hi everyone,
Actually i'm learning C#, and i have an assignment, to program a 3x3 puzzle, that where you have 8 pieces and 1 free slot, so you can move the pieces and solve it. Our teacher told us it must be done with picture boxes. I've been doing some research on the internet, and i found this code:

//------------- for Picture8 -----------

        private void Picture8_DragDrop(object sender, DragEventArgs e)
        {
            if ((e.Data.GetDataPresent(DataFormats.Bitmap)))
                this.Picture8.Image = (Bitmap)(e.Data.GetData(DataFormats.Bitmap));
        }

        private void Picture8_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.Bitmap))
                e.Effect = DragDropEffects.All;
            else
                e.Effect = DragDropEffects.None;
        }

        private void Picture8_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
                Picture8.DoDragDrop(Picture8.Image, DragDropEffects.All);
        }

//------------- for Picture9 -----------

        private void Picture9_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.Bitmap))
                e.Effect = DragDropEffects.All;
            else
                e.Effect = DragDropEffects.None;
        }

        private void Picture9_DragDrop(object sender, DragEventArgs e)
        {
            if ((e.Data.GetDataPresent(DataFormats.Bitmap)))
            {
                PictureAux.Image = Picture9.Image;
                this.Picture9.Image = (Bitmap)(e.Data.GetData(DataFormats.Bitmap));
            }
        }

        private void Picture9_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
                Picture9.DoDragDrop(Picture9.Image,DragDropEffects.All);
        }

i've used it,but it just copy the image from the picture box where i start dragging to the other picture box where i drop, for example it copies the image from Picture8 to Picture9. I need some help on how to reference to the first picture box from where i start draggin, and change it's Image. i mean, after copying the image from Picture8 to Picture9, I want to change Picture8's image, but i don't know how to acces it.
I'll really appreciate your help. thanks!

If you want to change the image itself you can set the picturebox Imgae property to a different image, using a location / using your image list as your array of images.

If you want to change the image itself you can set the picturebox Imgae property to a different image, using a location / using your image list as your array of images.

I appreciate your help, but what if i want to change the picture on the picture box from where i dragged the image, i mean... i drag the image from pictureBox_A to pictureBox_B so it is copied into it, but at the same time change the image of pictureBox_A to another picture. How can i do it inside the event of dragdrop. And in case i want it to work with more Picture Boxes, how can i know from where i am dragging the image so i can change that source's image.

Thank you again

Edited 6 Years Ago by Arturo32: n/a

This article has been dead for over six months. Start a new discussion instead.