views:

562

answers:

3

I am developing an ASP.NET Ajax form, and decided to make most of the site in one page, because it isn't a very involved site (it's more of a form). In the codebehind, I have been making my code more organized by adding regions to it (inside are the click events of the controls, etc).

When I expand a region, all the subroutines and child regions are expanded. Is there an option in Visual Studio to prevent this from happening? I'd like to be able to expand a region, and then expand the region or subroutine I'd like to edit, rather than contracting all the subroutines and child regions to prevent me from getting distracted by my fat code. :)

+1  A: 

Try the "key chord": Ctrl+M, Ctrl+O, then use Ctrl+M, Ctrl+M to expand one at a time.

Although, I do think regions are evil, and you should do something about the fat code ;)

Jim Burger
+1  A: 

These keyboard shortcuts should help. I believe you can collapse all regions and then, when you open one, it's child regions will remain collapsed. Not tested though.

Ctrl + M, Ctrl + M  Collapse or expand the block you?re currently in.
Ctrl + M, Ctrl + O  Collapse all blocks in the file
Ctrl + M, Ctrl + L  Expand all blocks in the file
Ben Hoffstein
+1  A: 

VS does not expand all nested regions by default. It keeps the state of the nested regions. There's no option in VS to have all nested regions collapsed or expanded explicitly when expanding a region.

You could use Ctrl-M Ctrl-L to toggle all regions in the file to collapsed and then use Ctrl-M Ctrl-M to navigate your way down the regions tree to the one you need.

You could also make use of the partial classes and split your codebehind in several source files.

Franci Penov
Thanks for the suggestion about using partial classes. :)
RodgerB