Wrox Home  

Topic: C# and C++

Beginning Object-Oriented Programming with C# (1118336925) cover image

Beginning Object-Oriented Programming with C#

Jack Purdum
ISBN: 978-1-118-33692-2
624 pages
November 2012
Other Available Formats: Wiley E-Text
If you are an instructor, you may request an evaluation copy for this title.
Paperback Version: US $39.99 Add to Cart

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 Errata Form. We will attempt to verify your error; if you're right, we will post a correction below.

ChapterPageDetailsDatePrint Run
32 Error in Text
Correction to Steps:
  1. From the File menu of the main menu options, select New Project
  2. 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.)
  3. You should see several C# templates in the center window. Select Empty Project.
  4. Towards the bottom of the list, change the name to Chapter02Program01.
  5. Change the Location to whatever directory name you wish to use for this program.
  6. 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.
  7. Click OK. The Solution Explorer window is opened for you, as is the Properties window for the project.
  8. 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.
  9. Now select Windows Form from the center panel as shown in Figure 2.9.
  10. 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.
  11. 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.
  12. 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.
  13. 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.
  14. 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.
  15. 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.
  16. 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.)
  17. 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.
  18. 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.
  19. Also change Startup object from Not set to frmMain.
  20. 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.
  21. 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.
439 Error in Text
The reference in paragraph 3 currently reads:

Figure 14-10

Should read:

Figure 14-11
Printer-Ready Version   Share This
With you wherever you go: pdf + ePub + kindle -- DRM-free