private void RefreshFieldsColors() { foreach (Control control in this.plBoard.Controls) { if (control is BoardFieldControl) { BoardFieldControl boardField = control as BoardFieldControl; boardField.CurrentColor = this.Game.Board[boardField.RowIndex, boardField.ColumnIndex]; } } this.plBoard.Refresh(); }
private void CreateFields() { this.plBoard.Width = 2 * BOARD_BORDER_WIDTH + this.Game.Board.Size * BoardFieldControl.SIZE; this.plBoard.Height = this.plBoard.Width; this.Width = 3 * DISTANCE_BETWEEN_CONTROLS + this.ctrlPlayer1.Width + this.plBoard.Width; this.Height = 2 * DISTANCE_BETWEEN_CONTROLS + Math.Max(this.plBoard.Height, this.lblMoveDuration.Bottom); this.MinimumSize = this.Size; this.MaximumSize = this.Size; Graphics graphics = this.plBoard.CreateGraphics(); Font numbersFont = new Font(this.plBoard.Font, FontStyle.Bold); int locationY = BOARD_BORDER_WIDTH - 1; for (int rowIndex = 0; rowIndex < this.Game.Board.Size; rowIndex++) { int locationX = BOARD_BORDER_WIDTH - 1; for (int columnIndex = 0; columnIndex < this.Game.Board.Size; columnIndex++) { BoardFieldControl field = new BoardFieldControl(this, rowIndex, columnIndex, this.Game.Board[rowIndex, columnIndex]); field.Location = new Point(locationX, locationY); this.plBoard.Controls.Add(field); #region Column Number if (rowIndex == 0) { string columnNumber = new string((char)('a' + columnIndex), 1); SizeF columnNumberSize = graphics.MeasureString(columnNumber, numbersFont); int columnNumberLocationX = locationX + (BoardFieldControl.SIZE - (int)columnNumberSize.Width) / 2; int columnNumberLocationY = (BOARD_BORDER_WIDTH - (int)columnNumberSize.Height) / 2; Label lblColumnNumber = new Label(); lblColumnNumber.Text = columnNumber; lblColumnNumber.Font = numbersFont; lblColumnNumber.AutoSize = true; lblColumnNumber.Location = new Point(columnNumberLocationX, columnNumberLocationY); this.plBoard.Controls.Add(lblColumnNumber); } #endregion locationX += BoardFieldControl.SIZE; } #region Row Number int rowNumber = rowIndex + 1; SizeF rowNumberSize = graphics.MeasureString(rowNumber.ToString(), numbersFont); int rowNumberLocationY = locationY + (BoardFieldControl.SIZE - (int)rowNumberSize.Height) / 2; int rowNumberLocationX = (BOARD_BORDER_WIDTH - (int)rowNumberSize.Width) / 2; Label lblRowNumber = new Label(); lblRowNumber.Text = rowNumber.ToString(); lblRowNumber.Font = numbersFont; lblRowNumber.AutoSize = true; lblRowNumber.Location = new Point(rowNumberLocationX, rowNumberLocationY); this.plBoard.Controls.Add(lblRowNumber); #endregion locationY += BoardFieldControl.SIZE; } }