Coding Skills for a Windows Form Application - How to work with the Text Editor toolbar
(Page 4 of 5 )
Figure 3-9 shows how you can use the Text Editor toolbar to work with code. If you experiment with this toolbar, you’ll find that its buttons provide some useful functions for working with comments and indentation and for moving from one place to another.
In particular, you can use the Text Editor toolbar to modify several lines of code at once. For example, during testing, you can use this toolbar to comment out several lines of code by selecting the lines of code and then clicking on the Comment button. Then, you can test the program without those lines of code. If necessary, you can use the Uncomment button to restore those lines of code. Similarly, you can use the Increase Indent and Decrease Indent buttons to adjust the indentation for selected lines of code.
You can also use the Text Editor toolbar to work with bookmarks. After you use the Toggle Bookmark button to mark lines of code, you can easily move between the marked lines of code by using the Next and Previous buttons. Although you usually don’t need bookmarks when you’re working with simple applications like the one shown here, bookmarks can be helpful when you’re working with applications that contain more than a few pages of code.
If you experiment with the other buttons on the Text Editor toolbar, you’ll find that they provide IntelliSense features like the ones you learned about earlier in this chapter for referring to properties, methods, and events. You can use these buttons to force Visual Studio to display a member list or information about a member that’s displayed in the Code Editor.
How to collapse or expand blocks of code
As you write the code for an application, you may want to collapse or expand some of the regions, comments, and methods to make it easier to scroll through the code and locate specific sections of code. To do that, you can use the techniques described in figure 3-9. In this figure, for example, the frmInvoiceTotal method has been collapsed so all you can see is its method declaration.
You may also want to collapse or expand code before you print it. Then, in the dialog box for the File->Print command, you can check or uncheck the Hide Collapsed Regions box. If this box is checked, Visual Studio will only print the code that’s displayed in the Code Editor.
The Code Editor and the Text Editor toolbar

Figure 3-9. How to use the Text Editor toolbar and collapse or expand code
How to use the buttons of the Text Editor toolbar
- To display or hide the Text Editor toolbar, right-click in the toolbar area and choose Text Editor from the shortcut menu.
- To comment or uncomment several lines of code, select the lines and click the Comment or Uncomment button. During testing, you can comment out coding lines so they won’t be executed. That way, you can test new statements without deleting the old statements.
- To increase or decrease the indentation of several lines of code, select the lines and click the Increase Indent or Decrease Indent button. Or, press the Tab and Shift+Tab keys.
- To move quickly between lines of code, you can use the last eight buttons on the Text Editor toolbar to set and move between bookmarks.
How to collapse or expand regions of code
- If a region of code appears in the Code Editor with a minus sign (-) next to it, you can click the minus sign to collapse the region so just the first line is displayed.
- If a region of code appears in the Code Editor with a plus sign (+) next to it, you can click the plus sign to expand the region so all of it is displayed.
Next: How to use code snippets >>
More C# Articles
More By Murach Publishing
|
This article is excerpted from chapter three of the book Murach's C# 2005, written by Joel Murach (Murach, 2005; ISBN: 9781890774370). Check it out today at your favorite bookstore. Buy this book now.
|
|