Section 2.3. Make the Editor Work for You


2.3. Make the Editor Work for You

The editor can be your most important tool for creating programs, yet few developers take the time to fully master it; and thus they miss out on potential gains in their productivity.


Note: The Visual Studio editor can be your most important tool for creating programs.

In this lab, you'll see how Visual Studio 2005 and several new features can work for you.

2.3.1. How do I do that?

The best way to explore the editor is to open a new Windows project. Let's call it EditorExploration. Visual Studio starts you out with a nice clean form named Form1, and also creates three additional files: Form1.cs to hold the code related to the form, Form1.designer.cs to hold the code created by the form designer, and Program.cs to hold the code related to the application.

Drag a label and a button anywhere onto the form, and then double-click the button to create an event handler. You should find that Visual Studio 2005 has opened a code-behind file named Form1.cs and has placed you inside the designer-generated button1_Click method.

2.3.1.1 Change your code

Make some minor changes to the code in your editor. Notice the yellow strip down the side of the window. This indicates changes to your code that have not yet been saved. When the changes are saved, this strip turns green.


Note: A yellow strip indicates unsaved changes. A green strip indicates changes that have been saved.
2.3.1.2 Use IntelliSense to complete your statement

Inside the button1_click method, type the letter l (lowercase L). IntelliSense leaps to the label1 member, which is just what you want. Insert a period (.) and IntelliSense will fill in the name label1 and open up all the public methods, properties, and so forth for that control.


Tip: By default, IntelliSense leaps to the member you are most likely to want to use (often determined by remembering the member you used most recently). You can turn this off in Tools Options Text Editor C# IntelliSense. Just unclick "IntelliSense pre-selects most frequently used members."

Now you can scroll to Text or you can start typing (te...), and IntelliSense will find Text for you. Pressing the Tab key will complete the word once it is found (it also will set the correct capitalization).

2.3.1.3 Find compile errors before you compile

Notice the red squiggle after the word Text. As in Visual Studio 2002 and 2003, the red squiggle warns of a parsing error, but now IntelliSense help is available to suggest how you can fix it. Hover your mouse pointer over the squiggle, and you will see a tool tip that suggests how to fix the error. In this case it says you want a semicolon, which of course you do not want, but much of the time it does provide a good clue as to how to fix the problem. Complete your statement as follows:

label1.Text = "Goodbye";

2.3.1.4 Use bookmarks to simplify navigation

In previous versions of Visual Studio you used bookmarks to mark lines of source code that you return to frequently. Visual Studio 2005 includes a Bookmark Navigation window that allows you to see and manipulate all your bookmarks by renaming them as well as enabling, disabling, and removing them. The Bookmark Navigation window also allows you to move among your bookmarks and to group them into folders of bookmarks.

As with earlier versions of Visual Studio, you place a bookmark on a line of code by positioning your mouse cursor on the line and choosing Edit Bookmarks Toggle Bookmark, by using the shortcut key combination, or (easiest) by just clicking the Bookmark button on the toolbar, as show in Figure 2-9.

Figure 2-9. Clicking the Bookmark button


To try this feature out, double-click Program.cs and place a bookmark on a line of code in that file as well. You can move through your bookmarks most easily by clicking the Next and Previous Bookmark buttons, which are next to the Bookmark Toggle button or you may open the Bookmark window (View Bookmark window), as shown in Figure 2-10.

Figure 2-10. The Bookmark Navigation window


2.3.1.5 Dock windows where you want them

While you are in the editor, drag one of the windows from its docked position. As soon as you begin to move the window around, the docking diamond appears, as seen in Figure 2-11.

Figure 2-11. Docking a window



Note: Another fast way to navigate among bookmarks is to open the Bookmarks window by selecting View Bookmarks Window.

As you move the window, the four arrows of the docking diamond point to where you can dock the window. If you place your cursor over one of the arrows, the arrow darkens and you can preview the window's placement. If the window can join a tabbed group, the center of the diamond darkens as you pass your cursor over it. Hover your cursor over the darkened center, release, and presto! Your window is tabbed.

2.3.1.6 Simplify actions with smart tags

Before we leave this lab, let's return to Design view and drag DataGridView from the Data tab on the Toolbox onto the form. As soon as you do, an Actions smart tag opens, as shown in Figure 2-12.

Figure 2-12. A smart tag


The Actions smart tag provides instant access to many of the most common actions you might want to take on this control, such as setting the format of the grid, setting a data source, editing or adding columns in the grid, and determining which actions will be allowed within the rows of the grid. This is a powerful supplement to the properties window, and makes working with the tools in the Toolbox much easier. Most controls have a smart tag; but the decision as to whether to have one is determined by the creator of the control.


Note: To create a tabbed window, click the center of the docking diamond.

2.3.2. What about . . .

...the hundreds of other nifty features in the editor?

The truth is that one could write a book just on the programming assistance the editor provides. In the next couple of labs we'll look at some of the more powerful features, including refactoring and the use of code snippets.


Note: I've added an arrow to Figure 2-12 to show you the smart tag drop-down button. When the smart tag is closed, clicking this button will reopen the smart tag.

2.3.3. Where can I learn more?

Good information about the code editor is available in the Help files, but the most powerful way to learn about the editor is to spend time playing in the editor and right-clicking various things to see what options are made available.


Note: I've added an arrow to Figure 2-12 to show you the smart tag drop-down button. When the smart tag is closed, clicking this button will reopen the smart tag.

2.3.4. Where can I learn more?

Good information about the code editor is available in the Help files, but the most powerful way to learn about the editor is to spend time playing in the editor and right-clicking various things to see what options are made available.



Visual C# 2005(c) A Developer's Notebook
Visual C# 2005: A Developers Notebook
ISBN: 059600799X
EAN: 2147483647
Year: 2006
Pages: 95
Authors: Jesse Liberty

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