Search code examples
c#winformspictureboxchess

moving picture in picturebox


hi friends im making a simple chess game.and i want to know how can i move between pictureboxes?i made 64 pictureboxes(for each place one picturebox) and for example i want to move the king piece that is in picturebox2 in the picturebox that is on top of the picturebox2.thanks for your help

for example like this:

 picturebox2.image=picturebox.image.up///move the image in picturebox into the picture box that is on top of the picturebox2

is it possible?


Solution

  • If the problem is "how to locate the field that's above the current field":

    You need to store your pictureBoxes not (just) as picturebox1 to pictureBox64, but (also) as a two-dimensional array: PictureBox[,] grid = new PictureBox[8,8];. (*)

    Then you need to find out where that 'current' field is in the grid. From there it's simple to calculate where the 'next' field would be (y=y+1). Watch out that you don't go over the edge of the field.

    (*) Although you might want to remember more per field than just the picturebox, such as what piece (if any) occupies that field?