Измените динамически создаваемый задний цвет pictureboxes
У меня возникла проблема с изменением заднего цвета динамически создаваемого pixturebox при нажатии на picturebox. Этот код должен изменить задний цвет "currentpiece", но это не так, или я что-то упускаю? Пожалуйста, любая помощь ценится
Что я уже пробовал:
private void PieceClick(object sender, EventArgs e) { RefressChessBoard(); //Get the properties of the picturebox selected CurrentPiece = (PictureBox)sender; if (PieceMove) { foreach (PictureBox chessPiece in AllPieces) { chessPiece.BackColor = Color.Transparent; chessPiece.Visible = false; } } if (!PromotePawn) { //get the x coordinate of the selected piece FromX = CurrentPiece.Left / 100; FromX = Convert.ToInt32(Math.Floor(FromX)); //get the y coordinate of the selected piece FromY = CurrentPiece.Top / 100; FromY = Convert.ToInt32(Math.Floor(FromY)); if (chessEngine.isPlayerPiece((byte)FromX, (byte)FromY)) { //Get the Piece that was selected PieceSelected = chessEngine.CurrentBoard.GetPieceAtPosition((byte)FromX, (byte)FromY); //Check if the player selected a pawn if (CurrentPiece.Name == enPieceType.WhitePawn.ToString() || CurrentPiece.Name == enPieceType.BlackPawn.ToString()) { PossibleMoves = chessEngine.GetMoves((byte)FromX, (byte)FromY); CurrentPiece.BackColor = Color.OliveDrab; PieceMove = true; } DisplayAllPossibleMoves(); } }