The Basics

Broadly speaking, a Visual Studio editor is a text editor (think word processor) that allows you to write specific output efficiently. A designer is a visual editor, allowing you to work with visual concepts directly instead of text. Many document types are supported by both designers and editors: You can build a form, for instance, by using the drag-and-drop convenience of the Windows Forms designer or by hand-crafting the code within a text editor; or you can build an XML file using the same mechanisms.

The Visual Studio text editor provides the core text-editing functionality for all of the editors. This functionality is then inherited and added upon to create editors specific for a given document type. Thus, you have a code editor for source code files, XML editor for markup, a CSS editor for style sheets, and so on.

Likewise, designers will manifest themselves in ways specific to their role. The HTML designer is part text editor and part graphical tool, and the Windows and web forms designers are superb WYSIWYG form builders.

The Text Editor

There are a few text-editing features that we all take for granted: selecting parts of an existing body of text, inserting text into a document, copying and pasting text, and so on. As you would expect, the text editor window supports all of these features in a way that will be familiar to anyone who has used a Windows-based word processor.

You select text, for instance, by using the following familiar actions:

  1. Place the cursor at the start of the text you want to select.

  2. While holding down the left mouse button, sweep the mouse to the end of the text you want selected.

  3. Release the left mouse button.

In addition to this "standard" selection method, the Visual Studio text editor also supports "column mode" selection. Instead of your selecting text in a linear fashion from left to right, line-by-line, column mode instead allows you to drag a selection rectangle across a text field. Any text character caught within the selection rectangle will be part of the selected text. This is called column mode because it allows you to create a selection area that captures columns of text characters instead of just lines. The procedure is largely the same:

  1. Place the cursor at the start of the text you want to select.

  2. While holding down the Alt key and the left mouse button, expand the bounds of the selection rectangle until it includes the desired text.

  3. Release the left mouse button and Alt key.

After you've selected text, you can copy, cut, or drag it to a new location within the text editor. As with text selection, the commands for cutting, copying, and pasting text remain unchanged from their basic, standard implementation in other Windows applications: You first select text and then cut or copy it using the Edit menu, toolbar, or the text editor's shortcut menu.

By dragging a text selection, you can reposition it within the current text editor; place it in another, previously opened text editor window; or even drag the selection into the command or watch windows.

Line Wrapping and Virtual Space

The default behavior of the text editor is not to automatically wrap any text for you. In other words, as you type, your text or code will simply keep trailing on to the right of the editor. If you exceed the bounds of the currently viewable area, the editor window will simply scroll to the right to allow you to continue typing. However, the text editor window can behave more like a word processor where the document content is typically constrained horizontally to its virtual sheet of paper.


With word wrapping turned on, Visual Studio will automatically wrap your text onto the next line. You can also have the IDE place a visual glyph, which indicates that a wrap has taken place. Both of these options are controlled on the Options dialog box, under the TextEditor, All Languages, General page (shown in Figure 6.1).

Figure 6.1. Editor Options dialog box.

If you override the default behavior, turn wrapping on, and then type a line of code that exceeds the editor's width, you can see that the editor window (see Figure 6.2) automatically wraps the source to fit within the boundaries of the window and provides an icon to the far right of the editor to indicate that a wrap has taken place. Word wrapping is useful for keeping all of your code in plain sight (without the need for scrolling horizontally).

Figure 6.2. Word wrapping in the editor.

The other option on the Text Editor Options dialog box, Enable Virtual Space, is a mutually exclusive feature to word wrapping. That is, you can enable virtual space or word wrapping, but not both. Virtual Space refers to the capability to type text anywhere within the editor window without entering a bunch of spaces or tabs in the text area. This feature is useful in situations in which you want to place, for example, a code comment to the right of a few lines of code. Instead of tabbing each code comment over (or padding spaces before them) to get them to indent and line up nicely, you can simply place the cursor at the exact column within the text editor where you want your comments to appear. See Figure 6.3 for an example; the code comments in the screenshot were not preceded by any spaces or tabs. They were simply typed directly into their current positions.

Figure 6.3. Virtual spacing in the editor window.

Visual Studio Designers

Designers are much more visual in nature than the text editors within Visual Studio; they provide a graphical perspective of a particular solution artifact. Thus, a form will appear within a designer just as it would to the end user: as visual constructs made up of buttons, borders, menus, and frames. The code to implement the items shown in a designer is actually written by Visual Studio itself.

Like the various editors, the designers are all similar in form and function. They occupy space within the tabbed documents area of the IDE (just as the editors do). They may take on different behaviors depending on their target use. The Windows Forms designer and the component designer both appear nearly the same, but there are subtle differences in their usage.

Microsoft Visual Studio 2005 Unleashed
Microsoft Visual Studio 2005 Unleashed
ISBN: 0672328194
EAN: 2147483647
Year: 2006
Pages: 195

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: