Click here to Skip to main content
15,888,195 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi friends,
i took 64 pictureboxes,each place have one picturebox.
i want to know how can i get the picturebox that king piece is there?

for example sth like this:

SQL
PictureBox[,] grid = new PictureBox[8, 8];
        public PictureBox getinfo(int i, int j)
        {
            return grid[i, j];
        }
Posted
Updated 27-Nov-10 4:25am
v2
Comments
Sandeep Mewara 27-Nov-10 10:30am    
Not clear.
arashmobileboy 27-Nov-10 10:35am    
i want to get the picturebox that king is there and with it i can guess the next movement of king
Toli Cuturicu 27-Nov-10 13:16pm    
Not clear at all.
Dr.Walt Fair, PE 27-Nov-10 13:16pm    
It sounds to me like you are trying to mix the position information with the graphics representation. That sounds like a design problem to me. I would separate them and then your problem should be trivial.

For example, keep a list of pieces and positions. With that you can easily determine where they are and where they can move. As part of the class representing the pieces, keep an image to represent it, so you can change images if you like and display the nearly automatically.
CPallini 27-Nov-10 17:08pm    
Does your program places the King somewhere in the picture box and then forgets it?
You are joking Mr. arashmobileboy. :-D

1 solution

Ok,

we've told you before, that the solution with the pictureboxes is not the best one (it really is the worst I can think of). You definitely should draw the rectangles on your own directly on the form without PictureBoxes.

For your question with the king piece, I would advice you to write a class structure where the king is a derived class of a class e.g. ChessFigure. You can then use an array e.g. ChessFigure[8,8] that represents your chess board. You can then check for each array field if a (and which) figure is placed on the field.

Try it this way. What you try doesn't seem right.

I hope you understand what I mean.

Good luck!
 
Share this answer
 

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