Section 2.6. Menus and Toolbars


2.6. Menus and Toolbars

The menus provide access to many of the commands and capabilities of Visual Studio 2005. The more commonly used menu commands are duplicated with toolbar buttons for ease of use.

The menus and toolbars are context-sensitive (the available selection is dependent on what part of the IDE is currently selected, and what activities are expected or allowed). For example, if the current active window is a code-editing window for a console window, the top-level menu commands are: File , Edit , View, Refactor, Project, Build, Debug, Data, Tools, Test, Window, Community, and Help.

Many of the menu items have keyboard shortcuts, listed adjacent to the menu item itself. These are comprised of one or more keys (referred to as a chord ), pressed simultaneously . Shortcut keys can be a huge productivity boost, because you can perform common tasks quickly, without removing your hands from the keyboard.

The following sections describe some of the more important menu items and their submenus, focusing on those aspects that are interesting and different from common Windows commands.

2.6.1. File Menu

The File menu provides access to a number of file-, project-, and solution- related commands. Many of these commands are content-sensitive.

As in most Windows applications, the New menu item creates new items to be worked on by the application.

2.6.2. Edit Menu

The Edit menu contains the text editing and searching commands that one would expect, but also includes commands useful in editing code. The most useful are discussed next .

2.6.2.1. Cycle Clipboard Ring

The Clipboard Ring is like copy-and-paste on steroids. You can copy a number of different selections to the Windows clipboard, using the Edit Cut (Ctrl-X) or Edit Copy (Ctrl-C) commands. Then use Ctrl-Shift-V to cycle through all the selections, allowing you to paste the correct one when it comes around.

Visual Studio Hot Keys can be changed systematically or individually; the ones referred to here and throughout this book are the "standard keys" used when programming in C#. Your mileage may vary.


This submenu item is context-sensitive and is visible only when editing a code window.

2.6.2.2. Find and Replace

Visual Studio 2005 includes a number of advanced Find and Replace options that you'll use frequently. The most common ones are discussed in this section.

Quick Find and Quick Replace . These are just slightly jazzed names for slightly jazzed versions of the typical Find and Replace. You can access Quick Find with Ctrl-F, and Quick Replace with Ctrl-H. Both commands call essentially the same dialog boxes, switchable by a tab at the top of the dialog box, as shown in Figure 2-6.

Figure 2-6. Find and Replace

The search string defaults to the text currently selected in the code window, or, if nothing is selected, to the text immediately after the current cursor location.

The Look in: drop-down offers the choice of the Current Document, All Open Documents, the Current Project, and the current method.

Search options can be expanded or collapsed by clicking on the plus/minus button next to Find Options. By default, Search hidden text is checked, which allows the search to include code sections currently collapsed in the code window. The Use checkbox allows the use of either regular expressions or wildcards .

Regular expressions are a language unto themselves , expressly designed for incredibly powerful and sophisticated searches. A full explanation of regular expressions is beyond the scope of this book. For a complete discussion of regular expressions, see the SDK documentation or Mastering Regular Expressions , Second Edition, by Jeffrey E. F. Friedl (O'Reilly, 2002).


If the Use checkbox is checked, then the Expression Builder button to the right of the Find what textbox becomes enabled, providing a very handy way to insert valid regular expression or wildcard characters .

Once a search string has been entered in the Find what: text box, the Find Next button becomes enabled. In Quick Find mode, there is also a Bookmark All button, which finds all occurrences of the search string and places a bookmark (described below) next to the code.

In Quick Replace mode, there is also a Replace with text box, and buttons for replacing either a single occurrence or all occurrences of the search string.

Find in Files . Find in Files (Ctrl-Shift-F) is a very powerful search utility that finds text strings anywhere in a directory or in subdirectories ( subfolders ). It presents the dialog box shown in Figure 2-7. Checkboxes present several self-explanatory options, including the ability to search using either wildcards or regular expressions.

Find Symbol . Clicking the Find Symbol command (Alt-F12) will bring up the Find Symbol dialog box , which allows you to search for symbols (such as namespaces, classes, and interfaces) and their members (such as properties, methods , events, and variables ). It also allows you to search in external components for which the source code is not available.

The search results will be displayed in a window labeled Find Symbol Results. From there, you can move to each location in the code by double-clicking on each result.

2.6.2.3. Go To ...

This command brings up the Go To Line dialog box, which allows you to enter a line number and immediately go to that line. It is context-sensitive and is visible only when editing a text window.

Figure 2-7. Find and Replace in Files

2.6.2.4. Find All References

This is somewhat similar to Find Symbol under Find and Replace, except that rather than searching for any symbol, it only allows searches for methods that are referenced elsewhere in the project.

2.6.2.5. Insert File As Text ...

This command allows you to insert the contents of any file into your source code, as though you had typed it in. It is context-sensitive and is visible only when editing a text window.

A standard file-browsing dialog box is presented for searching for the file to be inserted. The default file extension will correspond to the project language, but you can search for any file with any extension.

2.6.2.6. Advanced

The Advanced command is context-sensitive and is visible only when editing a code window. It has many submenu items. These include commands for:

  • Creating or removing tabs in a selection (converting spaces to tabs and vice versa)

  • Forcing selected text to uppercase or lowercase

  • Deleting horizontal whitespace

  • Viewing whitespace (making tabs and space characters visible on the screen)

  • Toggling word wrap

  • Commenting and uncommenting blocks of text

  • Increasing and decreasing line indenting

  • Incremental searching (see the next section, "Incremental search")

2.6.2.7. Incremental search

Incremental search allows you to search an editing window by entering the search string character by character. As each character is entered, the cursor moves to the first occurrence of matching text.

To use incremental search in a window, select the command on the Advanced submenu, or press Ctrl-I. The cursor icon will change to a binocular with an arrow indicating the direction of search. Begin typing the text string to search for.

The case sensitivity of an incremental search will come from the previous Find, Replace, Find in Files, or Replace in Files search (described earlier).

The search will proceed downward and left to right from the current location. To search backward, use Ctrl-Shift-I.

The key combinations listed in Table 2-1 apply to incremental searching.

Table 2-1. Incremental searching

Key combination

Description

Esc

Stop the search.

Backspace

Remove a character from the search text.

Ctrl-Shift-I

Change the direction of the search.

Ctrl-I

Move to the next occurrence in the file for the current search text.


2.6.2.8. Bookmarks

Bookmarks are useful for marking spots in your code and easily navigating from marked spot to marked spot. There are several context-sensitive commands on the Bookmarks submenu (listed in Table 2-2). Note that, unless you add the item to the task list, bookmarks are lost when you close the file, although they are saved when you close the solution (so long as the file was still open).

Table 2-2. Bookmark commands

Command

Description

Toggle Bookmark

Place or remove a bookmark at the current line. When a bookmark is set, a blue rectangular icon will appear in the column along the left edge of the code window.

Enable/Disable

Enables or disables the checkboxes for all bookmarks in the Bookmarks window (does not remove bookmarks).

Previous Bookmark

Move to the previous bookmark.

Next Bookmark

Move to the next bookmark.

Clear

Remove bookmark.

Previous Bookmark in Folder

Move to the previous bookmark in the folder.

Next Bookmark in Folder

Move to the next bookmark in the folder.

Previous Bookmark in Document

Move to the previous bookmark in the current document.

Next Bookmark in Document

Move to the next bookmark in the current document.

Add Task List Shortcut

Add an entry to the Task List (described later in the "View Menu" section) for the current line. When a task list entry is set, a curved arrow icon appears in the column along the left edge of the code window.


This menu item only appears when a code window is the current window.

2.6.2.9. Outlining

Visual Studio 2005 allows you to outline , or collapse and expand, sections of your code to make it easier to view the overall structure. When a section is collapsed, it appears with a plus sign in a box along the left edge of the code window. Clicking on the plus sign expands the region.

You can nest the outlined regions , so that one section can contain one or more other collapsed sections. There are several commands to facilitate outlining (shown in Table 2-3).

Table 2-3. Outlining commands

Command

Description

Hide Selection

Collapses currently selected text.

Toggle Outlining Expansion

Reverses the current outlining state of the innermost section in which the cursor lies.

Toggle All Outlining

Sets all sections to the same outlining state. If some sections are expanded and some collapsed, then all become collapsed.

Stop Outlining

Expands all sections. Removes the outlining symbols from view.

Stop Hiding Current

Removes outlining information for currently selected section.

Collapse to Definitions

Automatically creates sections for each procedure in the code window and collapses them all.

Start Automatic Outlining

Restarts automatic outlining after it has been stopped .


The default behavior of outlining can be set using the Tools Options menu item. Go to Text Editor, and then the specific language for which you want to set the options. The outlining options can be set for VB.NET under Basic VB Specific, for Visual Basic 2005 under Visual Basic 2005 Formatting, and for C++ under C/C++ Formatting.

2.6.2.10. IntelliSense

Microsoft IntelliSense technology makes the lives of programmers much easier. It has real-time, context-sensitive help available, which appears right under your cursor. Code completion automatically completes your thoughts for you, drastically reducing your typing. Drop-down-lists provide all methods and properties possible in the current context, available at a keystroke or mouse click.

Unlike previous versions of Visual Studio, IntelliSense now works in all code windows, including not only the Visual Basic 2005 code-behind files, but also within both server- (i.e., script) and client-side (i.e., HTML) code in content files.

The default IntelliSense features can be configured by going to Tools Options and then the language-specific pages under Text Editor.

Most of the IntelliSense features appear as you type inside a code window, or allow the mouse to hover over a portion of the code. In addition, the Edit IntelliSense menu item offers numerous commands, the most important of which are shown in Table 2-4.

Table 2-4. IntelliSense commands

Command

Description

List Members

Displays a list of all possible members available for the current context. Keystrokes incrementally search the list. Press any key to insert the highlighted selection into your code; that key becomes the next character after the inserted name . Use the Tab key to select without entering any additional characters.

This can also be accessed by right-clicking and selecting List Member from the context-sensitive menu.

Parameter Info

Displays a list of number, names, and types of parameters required for a method, sub, function, or attribute.

Quick Info

Displays the complete declaration for any identifier (such as a variable name or class name) in your code. This is also enabled by hovering the mouse cursor over any identifier.

Complete Word

Automatically completes the typing of any identifier once you type in enough characters to uniquely identify it. This only works if the identifier is being entered in a valid location in the code.

Insert Snippet

Displays a selection of code snippets to insert, such as the complete syntax for a switch case block or an if block.

Surround With

Displays a selection of code snippets to surround a block of code, such as a class declaration.


The member list presents itself when you type a dot operator following any class or member name.

Every member of the class is listed, and each member's type is indicated by an icon. There are icons for methods, fields, properties, events, and so forth. In addition, each icon may have a second icon overlaid to indicate the accessibility of the member: public, private, protected, and so on. If there is no accessibility icon, then the member is public.

If the member list does not appear, make sure that you have added all the necessary using statements.


Two of the subcommands under the IntelliSense menu item, Insert Snippet and Surround With, tap into a great feature to reduce typing and minimize errors: code snippets . A code snippet is a chunk of code that replaces an alias. A short alias is replaced with a much longer code snippet. For example, the alias switch would be replaced with:

 switch ( switch_on )     {        default:     } 

with the expression switch_on highlighted in yellow and the cursor in place, ready to type in your own expression. In fact, all the editable fields will be highlighted, and you can use the Tab key to navigate through them, or Shift-Tab to go backwards . Any changes made to the editable field are immediately propagated to all the instances of that field in the code snippet. Press Enter or Esc to end the field editing and return to normal editing.

To do a straight alias replacement, either select Insert Snippet from the menu, or more easily, press Ctrl-K, Ctrl-X. Alternatively, just type an alias in the code window and an IntelliSense menu will pop up with a list of aliases, with the current one highlighted.

Alternatively, a code snippet can surround highlighted lines of code, say with a for construct. To surround lines of code with a code snippet construct, highlight the code, then either select Surround With from the menu, or press Ctrl-K, Ctrl-S.

2.6.3. View Menu

The View menu is a context-sensitive menu that provides access to the myriad of windows available in the Visual Studio 2005 IDE. You will probably keep many of these windows open all the time; others you will use rarely, if at all.

The View menu is context-sensitive. For example, with an ASP.NET content file on the work surface, the first three menu items will be Code, Designer, and Markup, while the Code and Designer menu items will be omitted if looking at a code-behind file.

When the application is running, a number of other windows, primarily used for debugging, become visible or available. These windows are accessed via the Debug Windows menu item, not from the View menu item.

Visual Studio 2005 can store several different window layouts. In particular, it remembers a completely different set of open windows during debug sessions than it does during normal editing. These layouts are stored per- user , not per-project or per-solution.

2.6.3.1. Class View

The Class View (Ctrl-Shift-C) shows all the classes in the solution in a hierarchical manner. A typical Class View, somewhat expanded, is shown in Figure 2-8.

As with the Solution Explorer, any item in the class view can be right-clicked, which exposes a pop-up menu with a number of context-sensitive menu items. This can provide a convenient way to sort the display of classes in a project or solution, or to add a method, property, or field to a class.

The button on the left above the class list allows for sorting the classes listed, either alphabetically , by type, by access, or grouped by type. Clicking on the button itself sorts by the current sort mode, while clicking on the down arrow next to it presents the other sort buttons and changes the sort mode.

The button on the right above the class list allows you to create virtual folders for organizing the classes listed. These folders are saved as part of the solution in the .suo file.

These folders are virtual (that is, they are illusory). They are only used for viewing the list. As such, they have no effect on the actual items. Items copied to the folder are not physically moved, and if the folders are deleted, the items in them are not lost. Note that if you rename or delete an object from the code that is in a folder, you may need to manually drag the item into the folder again to clear the error node.

2.6.3.2. Code Definition

The Code Definition window (Ctrl-W, D) is used in developing web pages.

2.6.3.3. Error List

The Error List window (Ctrl-W, Ctrl-E), which is available in all editor views, displays errors, warnings, and messages generated as you edit and compile your project. Syntax errors flagged by IntelliSense are displayed here, as well as deployment errors. Double-clicking on an error in this list will open the offending file and move the cursor to the error location.

Figure 2-8. Class View window

2.6.3.4. Output

The Output window (Ctrl-Alt-O) displays status messages from the IDE, such as build progress. The Output window can be set to display by default when a build starts by going to Tools Options Projects and Solutions General and checking "Show Output window when build starts."

This window is available in all editor views.

2.6.3.5. Properties

The Properties window (F4) displays all the properties for the currently selected item. Some of the properties (such as Font) may have subproperties , indicated by a plus sign next to their entries in the window. The property values on the right side of the window are editable.

One thing that can be confusing is that certain items have more than one set of properties. For example, a Form content file can show two different sets of properties, depending on whether you select the source file in the Solution Explorer or the form as shown in the Design view.

A typical Properties window is shown in Figure 2-9.

Figure 2-9. Properties window

The name and type of the current object is displayed in the field at the top of the window. In Figure 2-9, it is an object named btnPage2 of type Button, contained in the System.Web.UI.WebControls namespace.

Most properties can be edited in place in the Properties window. The Font property has subproperties that may be set directly in the window by clicking on the plus sign to expand its subproperties, and then editing the subproperties in place.

The Properties window has several buttons just below the name and type of the object. The first two buttons on the left toggle the list by category or alphabetically. The next two buttons from the left toggle between displaying properties for the selected item and displaying events for the selected item. The rightmost button displays property pages for the object, if there are any.

Some objects have both a Properties window and property pages. The property pages display additional properties not shown in the Properties window.


The box below the list of properties displays a brief description of the selected property.

2.6.3.6. Task List

In large applications, keeping a to-do list can be quite helpful. Visual Studio 2005 provides this functionality with the Task List window .

2.6.3.7. Toolbox

The Toolbox command (Ctrl-Alt-X) displays the toolbox if it is not currently displayed. If it is currently displayed, nothing happensit does not toggle the display. To hide the toolbox, click on the X in the toolbox title bar.

2.6.3.8. Other windows

There are several other windows that have been relegated to a submenu called Other Windows. These include:



Bookmark window (Ctrl-K, Ctrl-W)

The Bookmark window displays bookmarks you create to allow you to return to a specific spot in your code quickly.



Command window (Ctrl-Alt-A)

The Command window is used to enter commands directly.



Document Outline (Ctrl-Alt-T)

The Document Outline displays the hierarchical structure of a web page or user control, including directives, script blocks, HTML elements, and server controls.



Macro Explorer (Alt-F8)

Visual Studio 2005 offers the ability to automate repetitive chores with macros. A macro is a set of instructions written in VB.NET, either created manually or recorded by the IDE, saved in a file. The Macro Explorer is the one of the main tools for viewing, managing, and executing macros. It provides access into the Macro IDE.



Object Browser (Ctrl-Alt-J)

The Object Browser is a tool for examining objects (such as namespaces, classes, and interfaces), and their members (such as methods, properties, variables, and events).



Resource View (Ctrl-Shift-E)

This window displays the resource files included in the project . Resources are nonexecutable data deployed with an application, such as icons and graphics, culture-specific text messages, and persisted data objects.



Server Explorer (Ctrl-Alt-S)

The Server Explorer allows you to access any server to which you have network access.

2.6.4. Refactor Menu

Refactoring is the process of taking code duplicated in various parts of your program and extracting them out to a callable method. This is an advanced procedure, so you won't see any refactoring in this book.

For details on refactoring, we highly recommend the book Refactoring: Improving the Design of Existing Code , by Fowler, et al. (Addison Wesley, 1999).


The Refactor menu item is available when you're looking at a code window for a web page, user control, or language source code file. It is also available from context menus when right-clicking on an identifier in a Class View, Object Browser, or Solution Explorer window.

The refactoring menu items will modify your codefor example, extracting common code to a method and then calling that method in the place from which it was extracted.

2.6.5. Project Menu

The Project menu provides functionality related to project management. It is only visible when the solution is selected in the Solution Explorer. All of the functionality exposed by the Project menu is also available in the Solution Explorer, by right-clicking on the solution.

2.6.6. Build Menu

The Build menu offers menu items for building the current project (highlighted in Solution Explorer) or the solution. It also exposes the Configuration Manager for configuring the build process.

2.6.7. Debug Menu

The Debug menu allows you to start an application with or without debugging, set breakpoints in the code, and control the debugging session.

2.6.8. Data Menu

This context-sensitive menu is visible only when in design mode when creating, for example, web applications.

2.6.9. Format Menu

The Format menu is visible only in design mode when creating, for example, web applications; further, the commands under it are context-sensitive to the control(s) currently selected.

2.6.10. Tools Menu

The Tools menu presents commands accessing a wide range of functionality, ranging from connecting to databases to accessing external tools to setting IDE options. Some of the more useful commands are described in the following sections.

2.6.10.1. Connect To Device

The Connect To Device command brings up a dialog box that allows you to connect to either a physical mobile device or an emulator.

2.6.10.2. Connect To Database

The Connect To Database command default brings up the dialog box that allows you to select a server, log in to that server, and connect to the database on the server. Microsoft SQL Server is the default database (surprise!), but the Change button allows you to connect to any number of other databases, including any for which there are Oracle or ODBC providers.

2.6.10.3. Code Snippets Manager

The Code Snippets Manager command (Ctrl-K, Ctrl-B) brings up the Code Snippets Manager dialog box, which allows you to maintain the code snippets (described previously in the "IntelliSense" section). This dialog box allows you to add or remove code snippets for any of the supported languages. You can also import code snippets and search online for code snippets.

2.6.10.4. Choose Toolbox Items

This command brings up the Choose Toolbox dialog box , allowing you to add COM components and custom controls. The details of doing so are beyond the scope of this book, but are covered in full in Programming ASP.NET by Jesse Liberty and Dan Hurwitz (O'Reilly, 2005).

2.6.10.5. External Tools

Depending on the options selected at the time Visual Studio 2005 was installed on your machine, you may have one or more external tools available on the Tools menu. These might include tools such as Create GUID or Dotfuscator Community Edition. (Use of these tools is beyond the scope of this book.)

The Tools External Tools ... command allows you to add additional external tools to the Tools menu. When selected, you are presented with the External Tools dialog box. This dialog box has fields for the tool title, the command to execute the tool, any arguments and the initial directory, as well as several checkboxes for different behaviors.

2.6.10.6. Performance Tools

This menu item exposes a wizard for benchmarking and tuning performance , as well as a command for starting a new performance session.

2.6.10.7. Import and Export Settings

This command brings up the Import and Export Settings dialog box , which is a wizard for importing and exporting IDE environment settings. With this wizard, you can transfer your carefully wrought IDE settings from one machine to the next.

2.6.10.8. Options

The Options command also brings up the Options dialog box that allows you to set a wide range of options, ranging from the number of items to display in lists of recently used items to HTML Designer options.

2.6.11. Window Menu

The Window menu is a standard Windows application Window command. It displays a list of all the currently open windows, allowing you to bring any window to the foreground by clicking on it. Note that all the file windows currently displayed in the IDE also have tabs along the top edge of the work surface, below the toolbars (unless you have selected MDI mode in Tools Options Environment General), and windows can be selected by clicking on a tab.

2.6.12. Help Menu

The Help menu provides access to a number of submenus.

If you are developing on a machine with enough horsepower, Dynamic Help is a wonderful thing. Otherwise, it can diminish the responsiveness of the IDE.



Learning C# 2005
Learning C# 2005: Get Started with C# 2.0 and .NET Programming (2nd Edition)
ISBN: 0596102097
EAN: 2147483647
Year: 2004
Pages: 250

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net