How can I move a picture that is inside a picturebox to another picturebox?
I want to use it for moving the pieces of chess game. I have a took picturebox for each place
You can just assign the Image displayed in one picture box to another picture box. If you then want to remove the image from the original picture box (so that it is not displayed twice), you can set its Image
property to null
(or, of course, you can assign any other image of your choice). Like so:
//Assign the image in one picture box to another picture box
mySecondPicBox.Image = myFirstPicBox.Image;
//Clear the image from the original picture box
myFirstPicBox.Image = null;
If you want to swap the images displayed in two picture boxes, you need to temporarily store one of the picture objects in a variable. So you can use very similar code, with a slight modification:
//Temporarily store the picture currently displayed in the second picture box
Image secondImage = mySecondPicBox.Image;
//Assign the image from the first picture box to the second picture box
mySecondPicBox.Image = myFirstPicBox.Image;
//Assign the image from the second picture box to the first picture box
myFirstPicBox.Image = secondImage;