Figure 2-30

To display the Error List window, select View→Error List.

You can double-click on an error message to open the source file and locate the position of the error. Once the error is located, press F1 for help.

Output Window

The Output window (View→Output) displays status messages for your application when you are debugging in Visual Studio 2008. The Output window is useful for displaying debugging messages in your application. For example, you can use the Console.WriteLine() statement to display a message to the Output window:

Console.WriteLine(DateTime.Now.ToString());

Figure 2-31 shows the message displayed in the Output window.

Figure 2-31

Designer Window

The Designer window enables you to visually design the UI of your application. Depending on the type of projects you are creating, the Designer displays a different design surface where you can drag and drop controls onto it. Figure 2-32 shows the Designer for creating different types of projects — Windows Forms (left), Windows Mobile (right), and Web (bottom left).

Figure 2-32

To switch to the code-behind of the application, you can either double-click on the surface of the designer, or right-click the item in Solution Explorer and select View Code. For example, if you are developing a Windows Forms application, you can right-click on a form, say Form1.cs, in Solution Explorer and select View Code. The code-behind for Form1 then displays (see Figure 2-33).

Figure 2-33

Code View

Code view is where you write the code for your application. You can switch between design view and code view by clicking on the relevant tabs (see Figure 2-34).

Figure 2-34

In Visual Studio, you can right-click on the tabs (see Figure 2-35) to arrange the code view either horizontally or vertically, to maximize the use of your monitor(s).

Figure 2-35

Figure 2-36 shows the code view and design view displaying horizontally.

Figure 2-36

Figure 2-37 shows the code view and design view displaying vertically.

Figure 2-37

Having multiple views at the same time is useful if you have a big monitor (or multiple monitors).

Code and Text Editor

Within the code view of Visual Studio 2008 is the Code and Text Editor, which provides several rich features that make editing your code easy and efficient, including:

□ Code Snippets

□ IntelliSense statement completion

□ IntelliSense support for object properties, methods and events

□ Refactoring support 

Code Snippets

The Code Snippet feature in Visual Studio 2008 enables you to insert commonly used code blocks into your project, thereby improving the efficiency of your development process. To insert a code snippet, right-click on the location where you want to insert the code snippet in the Code Editor, and select Insert Snippet (see Figure 2- 38).

Figure 2-38

Select the snippet category by clicking on the category name (see the top of Figure 2-39) and then selecting the code snippet you want to insert (see bottom of Figure 2-39).

Figure 2-39 

For example, suppose that you select the try code snippet. The following block of code will be inserted automatically:

private void Form1_Load(object sender, EventArgs e) {

 try {

 } catch (Exception) {

  throw;

 }

}

You can also use the Surround With code snippets feature. Suppose that you have the following statements:

private void Form1_Load(object sender, EventArgs e) {

 int num1 = 5;

 int num2 = 0;

 int result = num1 / num2;

}

The third statement is dangerous because it could result in a division-by-zero runtime error, so it would be good to wrap the code in a try-сatch block. To do so, you can highlight the block of code you want to put within a try-сatch block and right-click it. Select Surround With (see Figure 2-40), and then select the try code snippet.

Figure 2-40 

Your code now looks like this:

private void Form1_Load(object sender, EventArgs e) {

 try {

  int num1 = 5;

  int num2 = 0;

Вы читаете C# 2008 Programmer's Reference
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату
×