C# 24-Hour Trainer. Stephens Rod

Чтение книги онлайн.

Читать онлайн книгу C# 24-Hour Trainer - Stephens Rod страница 6

C# 24-Hour Trainer - Stephens Rod

Скачать книгу

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, Location, and Solution Name, click OK. The result should look like Figure 1.5.

Figure 1.5

      NOTE

      If you have previously edited a project, you can quickly reload it from the File menu's Recent Projects and Solutions submenu. You can also load a solution into the IDE by using File Explorer to double-click the solution's .sln file.

      The rest of this lesson deals with the features available in Visual Studio, some of which are displayed in Figure 1.5. Before you launch into an inventory of useful features, however, open the Debug menu and select Start Debugging. Or if you're in a hurry, just press F5.

Your first program should look like Figure 1.6. Admittedly this first program isn't very fancy, but by the same token you didn't need to do much to build it. All you did was press Ctrl+Shift+N and then F5!

Figure 1.6

      This first program may not seem terribly impressive, but there's a lot going on behind the scenes. C# has built a form with a bunch of useful features, including:

      ● A resizable border and a draggable title bar.

      ● Working minimize, maximize, and close buttons in the upper-right corner.

      ● A system menu in the upper-left corner that contains working Restore, Move, Size, Minimize, Maximize, and Close commands.

      ● An icon in the system taskbar that lets you minimize, restore, and close the program.

      ● The ability to use Alt+Tab and Flip3D (Win+Tab) to move between the application and others.

      ● Other standard window behaviors. For example, if you double-click the form's title bar it maximizes (or restores if it is already maximized), and if you press Alt+F4, the form closes.

      Unless you're an absolute beginner to Windows, you probably take all of these features for granted, but providing them is actually a huge amount of work. Not too long ago you would have had to write around 100 lines of code to provide a subset of those features. Now Visual Studio automatically builds a form that handles most of the details for you.

      You can still get in and change the way things work if you want to (for example, you can set a form's minimum and maximum allowed sizes), but usually you can ignore all of those issues and concentrate on your particular application instead of the Windows decorations.

      A Suitable Executable

      Whenever you run a program in the IDE, Visual Studio builds an executable program, normally in the project's bin\Debug subdirectory. You can run the executable by finding it in File Explorer and double-clicking it.

      Unfortunately that doesn't mean the executable can run on any old computer! If you copy that file to another computer, it won't run unless the .NET Framework runtime libraries have been installed there. If that computer has Visual Studio installed, you're all set, but if it doesn't you'll need to install the redistributable yourself.

      To install these libraries, go to Microsoft's download web page www.microsoft.com/downloads and search for “.NET Framework redistributable.” Pick the version that matches the

Скачать книгу