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!