C# 24-Hour Trainer. Stephens Rod. Читать онлайн. Newlib. NEWLIB.NET

Автор: Stephens Rod
Издательство: John Wiley & Sons Limited
Серия:
Жанр произведения: Зарубежная образовательная литература
Год издания: 0
isbn: 9781119065692
Скачать книгу
standards are.)

      Configuring the IDE

When you first run Visual Studio, the dialog shown in Figure 1.1 appears to let you configure the IDE. (You may also see a few other dialogs before that point asking you to log in to your Microsoft profile. You can create one if you don't already have one.)

Figure 1.1

      The dialog lets you pick settings for general development, Visual Basic, Visual C#, and so forth. Because you're going to be focusing on C# development, select that option.

      NOTE

      These settings determine such things as what keystrokes activate certain development features. You can certainly write C# programs with the Visual C++ settings, but we may as well use the same playbook, so when I say, “Press F5,” the IDE starts your program instead of displays a code window or whatever Visual C++ thinks F5 should do.

      The dialog also lets you pick a color scheme. Pick the one you think you'll like best (admittedly without getting to try them out) and click Start Visual Studio. (Then be ready to wait again because the initial configuration can take a while.)

      If you ever want to switch to different settings (for example, if you initially picked the Dark colors but then discovered that they give you a headache), you can always change them later.

      To change the settings, open the Tools menu and select Import and Export Settings to display the Import and Export Settings Wizard. You can use this tool to save your current settings, reload previously saved settings, or restore the settings to their default values.

      To reset the settings, select the Reset All Settings option on the wizard's first page and click Next.

On the next page, indicate whether you want to save your current settings. When you've made your choice, click Next to display the page shown in Figure 1.2. Select the Visual C# choice and click Finish.

Figure 1.2

      Then sit back and wait. Or better still, go get something to drink because this could take a while. Visual Studio has a lot of settings to reset, and it could take several minutes depending on how fast your computer is. (And how busy your computer is playing YouTube videos.)

      Building Your First Program

      Now that you've installed C#, you're ready to build your first program. Launch Visual Studio by double-clicking its desktop icon, selecting it from the system's Start menu, finding it with the Windows Search tool, or doing whatever you do to run programs on your version of Windows.

When it starts, Visual Studio should look more or less like Figure 1.3. You can use the links in the center pane to get more information about Visual Studio,NET, Azure, and whatever else Microsoft thinks is important today.

Figure 1.3

      You can use the links in the left pane to create a new project or open an existing project. You can also create a new project by opening the File menu, expanding the New submenu, and selecting Project. Or if you're in a hurry to create your first project, just press Ctrl+Shift+N.

      NOTE

      Often you have several ways to do something in Visual Studio. You may be able to use a menu command, keyboard shortcut, or toolbar button to do the same thing. Usually I'll just mention one or two ways to do something, such as creating a new project, but you'll probably discover other ways, too.

All of those methods display the New Project dialog shown in Figure 1.4. Expand the Visual C# project types folder on the left and select the template for the type of project that you want to build on the right. For most of this book, that will be a Visual C# Windows Forms Application.

Figure 1.4

      After you select a project type, you need to enter several pieces of information:

      ● Name– This is the application's name. Visual Studio creates a folder with this name to hold the program's files. It also uses this name for some key values in the project.

      ● Location– This is where you want Visual Studio to put the project's folder.

      ● Solution Name– If the Create Directory for Solution box is checked (which it is by default), Visual Studio creates a folder with this name at the location you entered. It then places the application's folder inside the solution's folder.

      So if the Create Directory for Solution box is checked, you get a filesystem layout that looks like this:

      SolutionFolder

      SolutionFiles

      ApplicationFolder

      ApplicationFiles

      If the Create Directory for Solution box is not checked, you get a filesystem layout that looks like this:

      ApplicationFolder

      ApplicationFiles

      NOTE

      A project typically includes the files that make up a single application. A solution can contain several projects. A solution is useful when you want to build applications that go closely together. For example, a project could contain one program that builds three-dimensional data sets, another that displays them, and a third that lets you print them from different points of view.

      Solutions are particularly useful if you want to build a library of routines plus an executable program to test the library.

      The applications you build in this book are single programs so they don't really need to be inside a separate solution folder. Most of the time, I uncheck the Create Directory for Solution box to keep my filesystem simpler.

      NOTE

      By default, Visual Studio places new projects in your Projects folder at some obscure location such as C: \Users\MyUserName\Documents\Visual Studio 2016\Projects. Later it can be hard to find these projects in File Explorer (for example, to make a copy).

      To make finding projects easier, set the location to something more intuitive such as the desktop or a folder on the desktop. In fact, you might want to make a folder to hold projects for this book and then give each lesson a subfolder.

      The next time you create a new project, Visual Studio will remember your last choice, so from now on it'll be easy to find your projects.

      If you open the New Project dialog while you have another project open, you'll see an additional dropdown that lists the choices Create New Solution and Add to Solution. The first choice closes the current solution and creates a new one. The second choice adds the new application to the solution you currently have open. Normally you'll want to create a new solution.

After you display the New Project dialog and enter a Name,