Step 1: Create a Project and Add a Table to Your Form
The first step in creating a matching game is to create the project and add a table to your form.
To create a project and add a table to your form
On the File menu, click New Project.
If you’re not using Visual Studio Express, you need to select a language first. From the Installed Templates list, select either C# or Visual Basic.
Click the Windows Forms Application icon, and then type MatchingGame as the name.
Set the form properties:
Change the form's Text property to Matching Game.
Change the size to 550 pixels wide by 550 tall by using the Size property or dragging until you see the correct size in the lower-left corner of the integrated development environment (IDE).
Drag a TableLayoutPanel control from the Toolbox, and then set its properties:
Set the BackColor property to CornflowerBlue. (Select the Web tab in the color picker to see the color names.)
Set the Dock property to Fill by clicking the drop-down button next to the property and clicking the large middle button.
Click the triangle button in the upper-right corner of the TableLayoutPanel to display the task menu.
Click Add Row twice to add two more rows, and then click Add Column twice to add two more columns.
Click Edit Rows and Columns to open the Column and Row Styles window. Select each of the columns, click the Percent button and set each column's width to 25 percent of the total width. Then select Rows from the drop-down box at the top of the window, and set each row's height to 25 percent. Click the OK button.
Your TableLayoutPanel should now have sixteen equal-size square cells.
Be certain that the TableLayoutPanel is selected in the form editor. While it's selected, open the Toolbox and double-click Label to add a Label control to the upper-left square. The Label control should now be selected in the IDE. Set its properties:
Set the BackColor property to CornflowerBlue.
Set the AutoSize property to False.
Set the Dock property to Fill.
Set the TextAlign property to MiddleCenter by clicking the drop-down button next to the property, and then clicking the middle button.
Click the Font property. An ellipsis button should appear.
Click the ellipsis button, and set the font to Webdings 72 point Bold.
Set the Text property to the letter c.
The upper-left cell in the TableLayoutPanel should now contain a big black box centered on a blue background.
The Webdings font is a font of icons that ships with the Microsoft Windows operating system. In your matching game, the player needs to match pairs of icons, so you use this font to display the icons to match. Instead of putting c in the Text property, try entering different letters to see what icons are displayed. An exclamation point is a spider, an uppercase N is an eyeball, and a comma is a chili pepper.
Select your Label control and copy it. (Press Ctrl+C or from the Edit menu, click Copy.) Then paste it. (Press Ctrl+V or from the Edit menu, click Paste.) Another label appears in the second cell in the TableLayoutPanel. Paste it again, and another label appears in the third cell. Keep pasting Label controls until all of the cells are filled.
If you paste too many times, the IDE adds a new row to the TableLayoutPanel so that it has a place to add your new Label control. You can undo it. To remove the new cell, press Ctrl+Z or on the Edit menu, click Undo.
Now your form is laid out. It should look the following picture.