
48
|
Chapter 2, Master the Editor
#9 Master Regions
HACK
region strategy can make it easier to find and understand files, whereas a
poorly defined strategy can lead to regions being more of a hindrance than
benefit.
The Regions Add-in
To enclose a piece of existing code in a region, you need to find the top of
the code, type in the
#region statement, and then find the bottom of the
code and type in the closing
#endregion statement. While this is not all that
difficult, wouldn’t it be nice to be able to simply highlight a section of code
and click a button that adds that code to a region? That is where the Regions
Add-in comes into play. Using the Regions Add-in, you can select a piece of
code using the mouse or keyboard and then right-click and select Add to
New Region.
First, you will need to download and install the Region Add-in from http://
www.codeproject.com/dotnet/RegionsAddIn.asp. After you have downloaded
and installed the add-in, you will see two new items on your right-click
menu. These are shown in Figure 2-18. (These items will be visible only
when you have text selected.)
If you select a block of code and then click the Add to New Region item, you
will see the dialog shown in Figure 2-19.
After entering a name in the dialog box and clicking OK, the add-in will
wrap the selected code in a region using the name you entered.
You can also use the add-in to add code into an existing region. Simply ...