How to: Navigate and Search in Visual C# Express

There are various ways to move through text or code in the Code Editor using Class View or the mouse and navigation keys.

The Class View window provides a view of your project based on classes instead of files, as in Solution Explorer. You can use Class View to quickly navigate to any class or class member in your project. To access Class View, click Class View on the View menu.

Class View

  • Use the arrow keys to move one character at a time, or the arrow keys in combination with the CTRL key to move one word at a time. Arrow keys move one line at a time also.

  • Click a location with the mouse.

  • Use the scroll bars or scroll wheel on the mouse to move through the text.

  • Use the HOME, END, PAGEUP, and PAGE DOWN keys.

  • Use CTRL+PAGE UP and CTRL+PAGE DOWN to move the insertion point to the top or bottom of the window, respectively.

  • Use CTRL+UP ARROW and CTRL+DOWN ARROW to scroll the view without moving the insertion point.

  • Use the Navigate Backward button to move the insertion point to previous locations in the active document, and the Navigate Forward button to return to more recent locations.

CTRL-TAB Navigation

At any given time you may have several active windows in a Visual C# project. To quickly navigate to a window, press CTRL+TAB to display a window that lists all of your active tools and source code windows. Move the arrow keys while holding down the CTRL key to select the window to display.

Alt Control Navigation Through Files

Moving the Insertion Point

Operations such as Incremental Search, Goto Line, Goto Definition, Beginning of Document, End of Document, Paste, and Insert File can move the insertion point a significant distance within the active document. The Navigate Backward and Navigate Forward buttons retain the last 20 locations of the insertion point.

The following sections describe other ways to move to specific sections and lines of code:

  • Navigation bar

  • Bookmarks in the Bookmarks Window

  • Comment tasks in the Task List

  • Incremental searches

  • Go to Line command

  • Go to Definition command

The Navigation bar consists of two combo boxes named Types and Members displayed at the top of the Code Editor, as shown in the following illustration.

Navigation Bar

The Navigation bar enables you to navigate directly to a particular class or type, or to a procedure or member within it. Not every project incorporates the Navigation bar. The following descriptions show you how to navigate through your code.

To shift focus from the Code Editor to the Navigation bar

  • Press the shortcut key combination CTRL+F2.

To return focus from the Navigation bar to the Code Editor

  • Press the ESC key.

To shift focus from item to item on the Navigation bar

  • Press the TAB key.

To select the Navigation bar item that has focus and return to the IDE

  • Press the ENTER key.

To navigate to a class or type

  • Click its name in the Class Name/Types combo box in the upper left corner of the document.

To navigate directly to a procedure in a class

  • Click a procedure in the Method Name/Members combo box in the upper right corner of the document.

Bookmarks help you navigate to sections of code more quickly. The following examples show you how to use bookmarks.

To add a bookmark

  1. In the Code Editor, select a line you want to return to at later time.

  2. In the Bookmarks window, click the Toggle Bookmark button

    -or-

    Press CTRL+K.

    A bookmark symbol displays in the left margin of the Code Editor to mark the line.

  3. Keep pressing CTRL+K to toggle a bookmark on and off.

To move through bookmarks in the active document

  1. In the Bookmarks window, click Next Bookmark to scroll to the next bookmark in your code.

    -or-

    Press CTRL+K and then CTRL+N to move to the next bookmark.

  2. Previous Bookmark to scroll to the preceding bookmark in your code to scroll to the next bookmark in your code.

    -or-

    Press CTRL+K and then CTRL+P to move to the previous bookmark.

    Note

    Another way to return to a location is by using the Navigate Backward and Navigate Forward buttons.

To remove all bookmarks from a document

  • In the Bookmarks window, click the Clear Bookmarks button.

    -or-

    Press CTRL+K, and then CTRL+L to erase all bookmarks from the active document.

    Note

    To delete a single bookmark, right-click the bookmark, and click Toggle Bookmark, or keep pressing CTRL+K until the bookmark is removed.

A comment task begins with the phrase //TODO and reminds you of code that requires completion. You can create comment tasks in your code that mark places to which you will need to return, and then navigate directly to those locations from the Task List.

To create and use a comment task

  1. In the View drop-down list, select Other Windows, and then Task List.

    The Task List grid displays a list of work items as well as their statuses.

  2. From the Comment drop-down list, select Comments.

    All comment tasks in the code of the active document display.

  3. Add a comment task to your code, type two forward slashes followed by a space and then the keyword TODO. For example: // TODO Finish this code!

    As soon as you type TODO, this task is automatically added to the Comments list in the Task List. As you change the text in the comment task, the Comments list automatically updates.

  4. Click on any comment task to navigate to its location in your code.

    For more information, see Task List (Visual Studio).

Incremental search helps you navigate directly to locations in the current document as you enter the search characters. The following instructions show you how to perform an incremental search.

  1. Select Advanced on the Edit menu, and click Incremental Search.

  2. Begin typing the characters of the string you wish to find.

    As you add characters, the Code Editor highlights the first matches found in the current document.

Quick Find

The Quick Find dialog is the easiest way to locate a particular text string, The following instructions show you how to perform an incremental search.

To navigate using incremental search

  • On the Edit menu, click Find and Replace, and click Quick Find, or press CTRL+F.

    Type the characters of the string you wish to find. Press ENTER or click Find Next to begin the search.

Go to Line command

The following instructions show you how to use the Go to Line command to move the insertion point to a specific line number.

To go to a specific line number

  1. With a document open in the Code Editor, on the Edit menu, click Go to Line.

  2. Type the line number you want to view.

Go to Definition command

The Go to Definition command navigates to the definition of a local class, method of variable. For example, if you define a method called MyMethod(), and then later in your code make a call to MyMethod(), you can navigate directly to the method using Go to Definition.

The following instructions show you how to find your local class declarations, methods, or variable definitions using the Go to Definition command.

To go to the definition for the procedure or variable called

  1. Select any call to a procedure or variable.

  2. Press F12.

    The Code Editor displays the definition of the member or variable.

  3. To return to the point of the call, press the Navigate Backward button.

    If the definition lies outside your project, its source is read and displayed in a console window.

See Also

Tasks

How to: Create a New Visual C# Express Application

How to: Create a C# Console Application

How to: Build and Execute Your Visual C# Application

Concepts

Designing a User Interface in Visual C#

Other Resources

Visual C# Express

Using the Visual C# Express IDE