Читать книгу C# 24-Hour Trainer - Stephens Rod - Страница 19

Section I
The Visual Studio IDE and Controls
Lesson 1
Getting Started with the Visual Studio IDE
Try It

Оглавление

In this Try It, you prepare for later work throughout the book. You locate web resources that you can use when you have questions or run into trouble. You create and run a program, explore the project's folder hierarchy, and make a copy of the project. You also get a chance to experiment a bit with the IDE, displaying new toolbars, moving windows around, and generally taking the IDE for a test drive and kicking the tires.

NOTE

Note that the solutions for this lesson's Try It and exercises are not all available on the book's website. The Try It and some of the exercises ask you to experiment with the IDE rather than produce a finished program, so there's really nothing to download. In later lessons, example solutions to the Try It and exercises are available on the book's website.

Lesson Requirements

In this lesson, you:

● Find and bookmark useful web resources.

● Launch Visual Studio and start a new Visual C# project.

● Experiment with the IDE's layout by displaying the Debug toolbar, pinning the Toolbox, and displaying the Output window.

● Run the program.

● Find the program's executable, copy it to the desktop, and run it there.

● Copy the project folder to a new location and make changes to the copy.

● Compress the project folder to make a backup.

NOTE

You can download the code and resources for this lesson from the website at www.wrox.com/go/csharp24hourtrainer2e.

Hints

● When you create a new project, be sure to specify a good location so you can find it later.

● Before you compress the project, remove the bin, obj, and .vs directories to save space.

Step-by-Step

● Find and bookmark useful web resources.

1. Open your favorite web browser.

2. Create a new bookmark folder named C#. (See the browser's documentation if you don't know how to make a bookmark folder.)

3. Go to the following websites and bookmark the ones you like (feel free to search for others, too):

● My C# Helper website (www.CSharpHelper.com)

● This book's web page (www.CSharpHelper.com/24hour.html)

● This book's Wrox web page (go to www.wrox.com and search for C# 24-Hour Trainer, Second Edition)

● Visual C# Express Edition MSDN forum (social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/threads)

● Visual C# IDE MSDN forum (social.msdn.microsoft.com/Forums/en-US/csharpide/threads)

● Visual C# Language MSDN forum (social.msdn.microsoft.com/Forums/en-US/csharplanguage/threads)

● Visual C# General MSDN forum (social.msdn.microsoft.com/Forums/en-US/csharpgeneral/threads)

● MSDN (msdn.microsoft.com)

● Stack Overflow (www.stackoverflow.com)

● Code Project (www.codeproject.com)

● Launch Visual Studio and start a new Visual C# project.

1. If you don't have a desktop or taskbar icon for Visual Studio, create one. For example, in Windows 8, follow these steps:

a. Open the Charms area, click Search, and type VS Express (or part of the name of the version you installed). If Visual Studio isn't in the result list, make sure the search box's dropdown list has Everywhere selected.

b. In the search results, right-click the program and select Pin to Start or Pin to Taskbar.

2. Launch Visual Studio by clicking the tile you just pinned to the start screen or the icon you just pinned to the taskbar.

3. Create a new project.

a. Press Ctrl+Shift+N or open the IDE's File menu, expand the New submenu, and select Project.

b. Expand the Visual C# project types folder and select the Windows Forms Application template.

c. Enter a project name and a good, easy-to-find location like the desktop or a folder named C# Projects on the desktop.

d. Uncheck the Create Directory for Solution box.

e. Click OK.

● Experiment with the IDE's layout by displaying the Debug toolbar, pinning the Toolbox, and displaying the Output window.

1. Open the Tools menu and select Customize. On the Customize dialog, select the Toolbars tab and check the box next to the Debug toolbar. Experiment with the other toolbars if you like. Close the dialog when you're done.

2. If the Toolbox is auto-hiding (it should be after you first install Visual Studio), float the mouse over it until it expands. Click the thumbtack to pin it.

3. To display the Output window, open the View menu and select Output. Grab the Output window's title bar and drag it around. Move it over some drop targets to see where it lands. When you're finished, drop it at the bottom of the IDE as shown in Figure 1.7.

● Run the program.

1. Press F5 or open the Debug menu and select Start Debugging.

2. Try out the form's minimize, maximize, and close buttons and the commands in the form's system menu. Move the form around and resize it. Marvel at the fact that you didn't need to write any code!

● Find the program's executable, copy it to the desktop, and run it there.

1. Start File Explorer and navigate to the location that you specified when you created the new program.

2. There you should find a folder named after the program. Open that folder and examine the files inside. Notice the .sln file that you can double-click to reopen the solution in Visual Studio. Notice also the bin, obj, and .vs directories.

3. Enter the bin directory and move into its Debug subdirectory. It contains several files including the executable, named after the program but with the .exe extension. Right-click the executable and select Copy.

4. Right-click the desktop and select Paste to copy the executable to the desktop.

5. Double-click the copy of the executable on the desktop.

● Copy the project folder to a new location and make changes to the copy.

1. In File Explorer, go to the directory that contains the project folder.

2. Right-click the project's folder and select Copy.

3. Right-click the desktop and select Paste to copy the project folder.

4. Open the copied project folder and double-click the .sln file to open the copied project in Visual Studio. If the form doesn't open in the Form Designer (#4 in Figure 1.7), look in Solution Explorer and double-click the file Form1.cs.

5. In the Form Designer, grab the handle on the form's lower-right corner and resize the form to make it tall and skinny.

6. Run the modified program. Then go back to the original project (which should still be running in another instance of Visual Studio) and run it. Notice that the two versions display forms of different sizes.

● Compress the project folder to make a backup.

1. In Visual Studio, close the project. (Or close Visual Studio.)

2. In File Explorer, return to the project's folder and delete the bin, obj, and .vs directories. (Note that you can't delete the bin directory if Visual Studio has the project open.)

3. Move up one level to the directory that contains the project folder. Right-click the folder, expand the Send To submenu, and select Compressed (Zipped) Folder.

4. E-mail copies of your first project to all of your friends and relatives. I'm sure they'll thank you!

C# 24-Hour Trainer

Подняться наверх