C# 24-Hour Trainer. Stephens Rod

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

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

C# 24-Hour Trainer - Stephens Rod

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

version if you just installed Visual Studio) and install it on the target computer.

      Now you can copy C# executables onto the other computer and run them.

      Copying Projects

      Sometimes you may want to copy a project. For example, you might want to save the current version and then make a new one to try things out. Or you may want to give a copy of the project to a friend or your programming instructor so he or she can tell you why its New button makes the program exit.

      You might look in Visual Studio's File menu and see the Copy As commands. Don't be tempted! Those commands copy single files, not the entire project. Later when you try to open one of those files, you'll discover that Visual Studio cannot find all of the other pieces that it needs and you'll be left with nothing usable.

      To correctly copy a project, copy the entire solution or application folder and its directory hierarchy. Alternatively, you can compress the project directory and then copy the compressed file. Just be sure that whatever copying method you use brings along all of the project's files.

      Note that you can delete the bin and obj subdirectories if you like to save space. Those directories contain files that Visual Studio creates when it loads and builds a program, and it will re-create them whenever it needs them later.

      You can also delete the .vs directory, which contains user settings. Unfortunately that directory is hidden by default so it may be hard to find. To make File Explorer show you hidden files, open the Control Panel, click Appearance and Personalization, and select Folder Options. On the View tab, select Show Hidden Files and Folders, and then click OK. Now you can see the .vs directory to delete it.

      NOTE

      Compressing a project is very useful because it keeps all of its files together in a package. In particular, if you ever need to e-mail a project to someone (for example, if you e-mail me at [email protected] for help), you can remove the bin, obj, and .vs directories, compress the project folder, and e-mail the package as a single file.

      If you're sending the project to your instructor as part of an assignment, rename the compressed file so it contains your name and the name of the assignment; for example, RodStephens6-1.zip.

      Exploring the IDE

      The Visual Studio IDE contains a huge number of menus, toolbars, windows, wizards, editors, and other components to help you build applications. Some of these, such as the Solution Explorer and the Properties window, you will use every time you work on a program. Others, such as the Breakpoints window and the Connect to Device dialog, are so specialized that it may be years before you need them.

Figure 1.7 shows the IDE with a simple project loaded and some of the IDE's most important pieces marked. The following list describes those pieces.

Figure 1.7

      1. Menus– The menus provide all sorts of useful commands. Exactly which commands are available, which are enabled, and even which menus are visible depends on what kind of editor is open in the editing area (#4). Some particularly useful menus include File (opening old projects and creating new ones), View (finding windows), Project (adding new forms and other items to a project), Debug (build, run, and debug the project), and Format (arrange controls on a form).

      2. Toolbars– The toolbars provide shortcuts for executing commands similar to those in the menus. Use the Tools menu's Customize command to determine which toolbars are visible.

      3. Solution Explorer– The Solution Explorer lists the files in the project. One of the most important is Form1.cs, which defines the controls and code for the form named Form1. If you double-click a file in the Solution Explorer, the IDE opens it in the editing area.

      4. Editing Area– The editing area displays files in appropriate editors. Most often you will use this area to design forms (place controls on them and set control properties) and write code for forms, but you can also use this area to edit other files such as text files, bitmaps, and icons.

      5. Toolbox– The Toolbox contains controls and components that you can place on a form. Select a tool and then click and drag to put a copy of the tool on the form. Notice that the Toolbox groups controls in tabs (All Windows Forms, Common Controls, Containers, Menus & Toolbars, and so on) to make finding the controls you need easier.

      6. Properties Window– The Properties window lets you set control properties. Click a control on the Form Designer (shown in the editing area in Figure 1.7) to select it, or click and drag to select multiple controls. Then use the Properties window to set the control(s) properties. Notice that the top of the Properties window shows the name (label1) and type (System.Windows.Forms.Label) of the currently selected control. The currently selected property in Figure 1.7 is Text, and it has the value First Name:. You'll spend a lot of time working with the Properties window.

      7. Property Description– The property description gives you a reminder about the current property's purpose. In Figure 1.7, it says that the Text property gives the text associated with the control. (Duh!)

      8. Other Windows– This area typically contains other useful windows. The tabs at the bottom let you quickly switch between different windows.

      Figure 1.7 shows a fairly typical arrangement of windows, but Visual Studio is extremely flexible so you can rearrange the windows if you like. You can hide or show windows, make windows floating or docked to various parts of the IDE, make windows part of a tab group, and make windows automatically hide themselves if you don't need them constantly.

      If you look closely at the right side of the title bar above one of the windows in Figure 1.7 (for example, the Properties window), you'll see three icons: a dropdown arrow (

), a thumbtack (
), and an X (
).

      If you click the dropdown arrow (or right-click the window's title bar), a menu appears with the following choices:

      ● Float– The window breaks free of wherever it's docked and floats above the IDE. You can drag it around and it will not re-dock. To make it dockable again, open the menu again and select Dock.

      ● Dock– The window can dock to various parts of the IDE. (This is kind of fun and I'll say more about it shortly.)

      ● Dock as Tabbed Document– The window becomes a tab in a tabbed area similar to #8 in Figure 1.7. Unfortunately, it's not always obvious which area will end up holding the window. To make the window a tab in a specific tabbed area, make it dockable and drag it onto a tab (described shortly).

      ● Auto Hide– The window shrinks itself to a small label stuck to one of the IDE's edges and its thumbtack icon turns sideways (

) to indicate that the window is auto-hiding. If you float the mouse

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