Esempio n. 1
0
        private void SetUp()
        {
            // Size the window suitably
            int formSize = (int)(2.5 * MarginSize) + (GridSize * TileSize);
            var size     = new Size(formSize, formSize);

            LockFormSize(size);

            // initialize the "chess board"
            _chessBoardPanels = new PieceBox[GridSize, GridSize];

            // double for loop to handle all rows and columns
            for (byte xCoord = 0; xCoord < GridSize; ++xCoord)
            {
                for (byte yCoord = 0; yCoord < GridSize; ++yCoord)
                {
                    // create new Panel control which will be one
                    // chess board tile
                    var newPieceBox = new PieceBox(new GridLocation(xCoord, yCoord))
                    {
                        Size     = new Size(TileSize, TileSize),
                        Location = new Point(TileSize * xCoord + MarginSize, TileSize * yCoord + MarginSize),
                        SizeMode = PictureBoxSizeMode.StretchImage,
                    };
                    newPieceBox.Click += newPieceBox_Click;

                    Controls.Add(newPieceBox);

                    _chessBoardPanels[xCoord, yCoord] = newPieceBox;
                }
            }

            ClearHighlights();
            Show();
        }
Esempio n. 2
0
        void newPieceBox_Click(object sender, EventArgs e)
        {
            PieceBox clickedSquare = sender as PieceBox;

            if (clickedSquare == null)
            {
                return;
            }

            if (SquareClicked != null)
            {
                SquareClicked(this, clickedSquare.GridLocation);
            }
        }