2010-11-22 97 views
-1

嗨朋友 即時製作一個簡單的國際象棋game.and我想知道如何可以在pictureboxes之間移動?我做了64個pictureboxes(每個地方一個picturebox),例如我想移動王片這是在picturebox2在是在picturebox2.thanks頂部的幫助picturebox中的移動圖片

例如像這樣在PictureBox:

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

這可能嗎?

+0

請不要發佈重複的問題:http://stackoverflow.com/questions/4243162/moving-a-picture-that-is-inside-a-picturebox-to-another-picturebox – 2010-11-22 10:45:26

+0

@Cody Gray:this是不同的question.i不想手動移動圖片,我想它自動 – Arash 2010-11-22 10:55:44

+1

你可能想解釋你的問題多一點:你想知道如何將picturebox1的圖像設置爲picturebox2的圖像,或者是關於如何找到位於第一個之上的picturebox的問題? – 2010-11-22 12:38:34

回答

2

如果問題是「如何定位這是當前字段上面的字段」:

你需要不(僅僅)存儲您pictureBoxes爲picturebox1到pictureBox64,而且也要作爲一個二維數組:PictureBox[,] grid = new PictureBox[8,8];。 (*)

然後,您需要找出「當前」字段在網格中的位置。從那裏可以很容易地計算'next'字段的位置(y = y + 1)。注意你不要越過場地的邊緣。

(*)儘管您可能想要記住每個字段比單個圖片框更多,比如哪個字段(如果有)佔據該字段?

+0

感謝上帝t,h,在一個人明白我的意思,[7,7]不應該[8,8]?你能幫我一點,我該如何採取現在的地方?非常感謝 – Arash 2010-11-26 07:39:51

+1

@arash:一邊有8個字段(所以[8,8]是正確的),編號(在代碼中)從0到7。 – 2010-11-26 15:43:34