Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,
I'm making a simple chess game with 3pieces just 2king and one queen in c# 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:
C#
picturebox2.Image = picturebox.Image //move the image in picturebox into the picture box that is on top of the picturebox2


Is this possible?
Posted
Updated 22-Nov-10 1:18am
v5
Comments
Dalek Dave 22-Nov-10 7:36am    
Yes, it is entirely possible.
But only a mad man would attempt it!

1 solution

Please, forget about your 64 (OMG!) pictureboxes and draw the board yourself.
Check out this[^] excellent CodeProject article for details on drawing the board and for the chess game implementation at all!

[UPDATE - After the comment from OP]
Well, it didn't changed anything for me. Personally I'd draw the board myself, because the PictureBox control is very very inefficient! But, if you want to go with it OK.
So you could set the image of a given picturebox by using its Image property:
C#
// Now suppose that we have to move a piece from "pictureBox2" to "pictureBox1"

// If we assume that "pictureBox2" contains the image of the correct piece to move then:

// First set the image for "pictureBox1"
pictureBox1.Image = pictureBox2.Image;

// And clear the image of "pictureBox2"
pictureBox2.Image = null;

// Now, if we assume that you set correct background colors for your pictureboxes (so they form a chess board) this code above should move the piece


I must tell you that personally I would NEVER do things like this and that's way I've provided a link to an excellent article which contains chess game logic and board drawing implementation in C#.
[/UPDATE]
 
Share this answer
 
v2
Comments
JF2015 22-Nov-10 7:07am    
Good Advice!
arashmobileboy 22-Nov-10 7:17am    
i edited my qusetion did it chang your idea?
Dalek Dave 22-Nov-10 7:36am    
Excellent answer!
arashmobileboy 22-Nov-10 7:45am    
thanks for your idea,now where sholud i use this code?i used it in picturebox_click event and when i click on picturebox1 it hides the piece,whats the problem?
arashmobileboy 22-Nov-10 7:51am    
ok thanks,solved

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900