Collapsing Your Code with Outlining

Keyboard:  CTRL + M, CTRL + M
Menu:  Edit -> Outlining -> Toggle Outlining Expansion
Command:  Edit.ToggleOutliningExpansion
Versions:  2008,2010
Published:  3/15/2010
Code:  vstipEdit0029

 

By default, Outlining is enabled in Visual Studio.  It's the line you see with the boxes to indicate the status of the area (collapsed or expanded):

image

 

You can collapse areas of code to get them out of your way so you can focus on other areas.  There are four ways to do it:

  1. Click on the minus sign to collapse an area of code:

    image

    NOTE:  In VS2010 it now highlights the area that will be collapsed as seen here.  A very cool feature.  If you don't like the highlighting color you can go to Tools -> Options -> Environment -> Fonts and Colors -> Collapsible Region to change it.

  2. VS2010 ONLY:  Click ANYWHERE on the vertical line in the highlighted region.  In other words, you can now collapse a region from anywhere in that region:
    image 

  3. Click anywhere in the area to be collapsed and hit CTRL + M, CTRL + M

  4. Click anywhere in the area to be collapsed and go to Edit -> Outlining -> Toggle Outlining Expansion on the Menu Bar

 

Once collapsed, the code area will look like this:

image