I’m building a virtual board game, and I need to be able to click on the pieces to move them. The board is created as a picture in the background, and the pieces are pictureboxes over top of that. More specifically, they are a custom class GamePiece that inherits from PictureBox. I know PictureBox has a Name_Click method that is called when it’s clicked, but I’m creating my pieces programatically, as follows:
public Player(int identity, GameBoard Board)
{
ID = identity;
for (int i = 0; i < 4; i++)
{
Pieces[i] = new GamePiece(ID, Board.GetPlaceSize(), Board.GetPieceColor(ID), Board);
}
}
Therefore, I don’t want to hardcode in methods to be called for each Gamepiece, because that would defeat my purpose here.
Any suggestions? I can include any other code that would be helpful, and I’m pretty flexible as far as redesigning code, if that would make my life easier later. Thanks in advance.
Just add
Control.Clickevent handler for your control:on the
Clickevent:or using
Anonymous Methods: