Do you think you've discovered an error in this book?
Please check the list of errata below to see if we've already addressed the error. If not,
please submit the error via our
We will attempt to verify your error; if you're right, we will post a correction below.
||Error in Text
Correction to Steps:
- From the File menu of the main menu options, select New Project
- From New Projects Dialog, select:
Installed --> Templates --> Visual C# --> Windows
You should see a window similar to Figure 2.8. (If you are using Visual
Studio 2012 Express, there will be fewer options in the center panel of
the dialog box than shown in Figure 2.8.)
- You should see several C# templates in the center window. Select Empty Project.
- Towards the bottom of the list, change the name to Chapter02Program01.
- Change the Location to whatever directory name you wish to use for this program.
- The Solution Name defaults to the application name (e.g., Chapter02Program01), but you can change it if you wish. I usually uncheck the Create directory for solution option. If you have one directory where you want all your test code to reside, then leave it checked so a directory is created for each project.
- Click OK. The Solution Explorer window is opened for you, as is the Properties window for the project.
- From the main menu, click Project --> Add Windows Form. By default, Visual Studio selects the Installed --> Visual C# Items menu option, so your screen should look similar to Figure 2.9.
- Now select Windows Form from the center panel as shown in Figure 2.9.
- Change the Name field at the bottom of the dialog box to frmMain.cs and click Add. Visual Studio creates the new form and adds it to the project. The Source window displays some source code that is automatically generated by Visual Studio. Visual Studio now displays either an empty form or some source code it created. What you see depends upon some internal variables that Visual Studio maintains from previous sessions.
10a. If you see a form, double-click on the form to switch to the source code.
10b. If you see program code, you are where you need to be.
- Place your cursor in the Source window and press Ctrl-A to highlight all of the code in the Source window. Now press the Delete key on your keyboard.
- Now type in the code shown in Listing 2-1 into the Source window. The code in Listing 2-1 is used in almost every program you will write, so you might want to make a copy of it and save it in a place where you can recall it for later reuse.
- As in Step 10, what you do now depends upon some internal variables used by Visual Studio. If you look in the Solution Explorer window and see that some references have been added to the Reference folder (e.g., System, System.Windows.Forms, etc.), proceed to Step 14. If there are no reference, follow Step 13a.
13a. Go to the main menu and select Project --> Add Reference. Once
the Reference Manager dialog appears, make sure the Assemblies
--> Framework menu sequence is select. (It is the default.) Scroll
the list presented in the center window until you see System.
13b. Click on System, and check the box that appears to the left of
System. This means that the System library will be added to
your project. Every program you write will use this library.
13c. Now scroll down further until you see System.Windows.Forms.
Click on that library and check the box so it, too, is added to
your project. Now click OK.
- In the Solution Explorer window, click on the small triangle just to the left of the frmMain.cs form you just added to the project. When you do this, you will see a file named frmMain.Designer.cs has been automatically added to your project. Click on the file and press the Delete key to remove the file from the project. (Visual Studio will ask you to confirm the deletion.)
- Go to the main menu and select the Project --> Chapter02Program01 Properties menu selection. The projects Properties always is the last item in the Project menu. You can also get to the applications Properties by pressing Alt-F7. The Application submenu will show choices similar to those seen in Figure 2-10.
- Change the Output type option by clicking the drop down list option (click the small down-arrow at the end of the Output type field) to Windows Application.
- Also change Startup object from Not set to frmMain.
- If you can click on the green Start arrow now and the empty form appears, you will NOT have to perform the next step. However, some early Beta versions of Visual Studio 2012 had a bug that prevented the program from running correctly. The following instructions will likely fix the bug.
18a. If you look in the Properites window (as indicated by the
Chapter02Program01 tab at the top of the Source window),
the fourth option below the Application option is named
Debug. Click on Debug to show the debugging options.
18b. Uncheck the Enable the Visual Studio hosting process.
18c. Check the Enable native code debugging
18d. Now click the Start button on the main menu. The program should
show an empty form.
||Error in Text
The reference in paragraph 3 currently reads: