The IDE of Visual Studio 2008 contains numerous components, and it will take you a while to explore them. It’s practically impossible to explain in a single chapter what each tool, window, and menu command does. We’ll discuss specific tools as we go along and as the topics get more and more advanced. In this section, I will go through the basic items of the IDE — the ones we’ll use in the following few chapters to build simple Windows applications.
The IDE Menu
The IDE menu provides the following commands, which lead to submenus. Notice that most menus can also be displayed as toolbars. Also, not all options are available at all times. The options that cannot possibly apply to the current state of the IDE are either invisible or disabled. The Edit menu is a typical example. It’s quite short when you’re designing the form and quite lengthy when you edit code. The Data menu disappears altogether when you switch to the code editor — you can’t use the options of this menu while editing code. If you open an XML document in the IDE, the XML command will be added to the main menu of Visual Studio.
The File menu contains commands for opening and saving projects or project items, as well as commands for adding new or existing items to the current project. For the time being, use the New > Project command to create a new project, Open Project/Solution to open an existing project or solution, Save All to save all components of the current project, and the Recent Projects submenu to open one of the recent projects.
The Edit menu contains the usual editing commands. Among these commands are the Advanced command and the IntelliSense command. Both commands lead to submenus, which are discussed next. Note that these two items are visible only when you’re editing your code, and are invisible while you’re designing a form.
Edit > Advanced Submenu
The more-interesting options of the Edit > Advanced submenu are the following:
View White Space – Space characters (necessary to indent lines of code and make it easy to read) are replaced by periods.
Word Wrap – When a code line’s length exceeds the length of the code window, the line is automatically wrapped.
Comment Selection/Uncomment Selection – Comments are lines you insert between your code’s statements to document your application. Every line that begins with a single quote is a comment; it is part of the code, but the compiler ignores it. Sometimes, we want to disable a fewlines fromour code but not delete them (because we want to be able to restore them later). A simple technique to disable a line of code is to comment it out (insert the comment symbol in front of the line). This command allows you to comment (or uncomment) large segments of code in a singlemove.
Edit > IntelliSense Submenu
The Edit > IntelliSense menu item leads to a submenu with five options, which are described next. IntelliSense is a feature of the editor (and of other Microsoft applications) that displays as much information as possible, whenever possible. When you type the name of a control and the following period, IntelliSense displays a list of the control’s properties and methods, so that you can select the desired one, rather than guessing its name. When you type the name of a function and the opening parenthesis, IntelliSense will display the syntax of the function — its arguments.
The IntelliSense submenu includes the following options:
List Members – When this option is on, the editor lists all the members (properties, methods, events, and argument list) in a drop-down list. This list will appear when you enter the name of an object or control followed by a period. Then you can select the desired member from the list with the mouse or with the keyboard. Let’s say your form contains a control named TextBox1 and you’re writing code for this form. When you enter the name of the control followed by a period (TextBox1.), a list with the members of the TextBox control will appear (as seen in Figure 1.12).
Figure 1.12 – Viewing the members of a control in the IntelliSense drop-down list
In addition, a description of the selected member is displayed in a ToolTip box, as you can see in the same figure. Select the Text property and then enter the equal sign, followed by a string in quotes, as follows:
If you select a property that can accept a limited number of settings, you will see the names of the appropriate constants in a drop-down list. If you enter the following statement, you will see the constants you can assign to the property (see Figure 1.13):
TextBox1.TextAlign =Code language: VB.NET (vbnet)
Figure 1.13 – Viewing the possible settings of a property in the IntelliSense drop-down list
Again, you can select the desired value with the mouse. The drop-down list with the members of a control or object (the Members list) remains open until you type a terminator key (the Esc or End key) or select a member by pressing the space bar or the Enter key.
Parameter Info – While editing code, you can move the pointer over a variable, method, or property and see its declaration in a yellow pop-up box. You can also jump to the variable’s definition or the body of a procedure by choosing Go To Definition from the context menu that will appear if you right-click the variable or method name in the code window.
Quick Info – This is another IntelliSense feature that displays information about commands and functions. When you type the opening parenthesis following the name of a function, for example, the function’s arguments will be displayed in a ToolTip box (a yellow horizontal box). The first argument appears in bold font; after entering a value for this argument, the next one is shown in bold. If an argument accepts a fixed number of settings, these values will appear in a drop-down list, as explained previously.
Complete Word – The Complete Word feature enables you to complete the current word by pressing Ctrl+spacebar. For example, if you type TextB and then press Ctrl+spacebar, you will see a list of words that you’re most likely to type (TextBox, TextBox1, and so on).
Insert Snippet – This command opens the Insert Snippet window at the current location in the code editor window. Code snippets, which are an interesting feature of Visual Studio 2008, are discussed in the section ‘‘Using Code Snippets’’ later in this chapter.
Edit > Outlining Submenu
A practical application contains a substantial amount of code in a large number of event handlers and custom procedures (subroutines and functions). To simplify the management of the code window, the Outlining submenu contains commands that collapse and expand the various procedures.
Let’s say you’re finished editing the Click event handlers of several buttons on the form. You can reduce these event handlers to a single line that shows the names of the procedures and a plus sign in front of them. You can expand a procedure’s listing at any time by clicking the plus sign in front of its name. When you do so, a minus sign appears in front of the procedure’s name, and you can click it to collapse the body of the procedure again. The Outlining submenu contains commands to handle the outlining of the various procedures, or turn off outlining and view the complete listings of all procedures. You will use these commands as you write applications with substantial amounts of code:
Toggle Outlining Expansion – This option lets you change the outline mode of the current procedure. If the procedure’s definition is collapsed, the code is expanded, and vice versa.
Toggle All Outlining – This option is similar to the Toggle Outlining Expansion option, but it toggles the outline mode of the current document. A form is reduced to a single statement. A file with multiple classes is reduced to one line per class.
Stop Outlining – This option turns off outlining and adds a new command to the Outlining submenu, Start Automatic Outlining, which you can select to turn on automatic outlining again.
Collapse To Definitions – This option reduces the listing to a list of procedure headers.
This menu contains commands to display any toolbar or window of the IDE. You have already seen the Toolbars menu (in the ‘‘Starting a New Project in Visual Basic 2008’’ section). The Other Windows command leads to a submenu with the names of some standard windows, including the Output and Command windows. The Output window is the console of the application. The compiler’s messages, for example, are displayed in the Output window. The Command window allows you to enter and execute statements. When you debug an application, you can stop it and enter VB statements in the Command window.
This menu contains commands for adding items to the current project (an item can be a form, a file, a component, or even another project). The last option in this menu is the Project Properties command, which opens the project’s Properties Pages. The Add Reference and Add Web Reference commands allow you to add references to .NET components and web components, respectively.
The Build menu contains commands for building (compiling) your project. The two basic commands in this menu are Build and Rebuild All. The Build command compiles (builds the executable) of the entire solution, but it doesn’t compile any components of the project that haven’t changed since the last build. The Rebuild All command does the same, but it clears any existing files and builds the solution from scratch.
This menu contains commands to start or end an application, as well as the basic debugging tools. The basic commands of this menu are discussed briefly in Chapter “GUI Design and Event-Driven Programming in Visual Basic 2008” and in the section “Debugging and Error Handling in VB 2008”.
This menu contains commands you will use with projects that access data. You’ll see how to use this short menu’s commands in the discussion of the visual database tools in Chapters 21 and 22 of the tutorial.
The Format menu, which is visible only while you design a Windows or web form, contains commands for aligning the controls on the form. The commands of this menu are discussed in Chapter “GUI Design and Event-Driven Programming in VB”. The Format menu is invisible when you work in the code editor — its commands apply to the visible elements of the interface.
This menu contains a list of useful tools, such as the Macros command, which leads to a submenu with commands for creating macros. Just as you can create macros in a Microsoft Office application to simplify many tasks, you can create macros to automate many of the repetitive tasks you perform in the IDE. The last command in this menu, the Options command, leads to the Options dialog box, in which you can fully customize the environment. The Choose Toolbox Items command opens a dialog box that enables you to add more controls to the Toolbox. In Chapter, ‘‘Building Custom Windows Controls in Visual Basic 2008’’ you’ll learn how to design custom controls and add them to the Toolbox.
This is the typical Window menu of any Windows application. In addition to the list of open windows, it also contains the Hide command, which hides all toolboxes, leaving the entire window of the IDE devoted to the code editor or the Form Designer. The toolboxes don’t disappear completely; they’re all retracted, and you can see their tabs on the left and right edges of the IDE window. To expand a toolbox, just hover the mouse pointer over the corresponding tab.
This menu contains the various help options. The Dynamic Help command opens the Dynamic Help window, which is populated with topics that apply to the current operation. The Index command opens the Index window, in which you can enter a topic and get help on the specific topic.