Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding the regions in Visual Studio

Tags:

I know VS code folding issues are an old chestnut, but I haven't been able to find this in all the other discussions I have browsed through:

We have a team of C# guys, some love regions and others hate them and we don't seem to have much middle ground to work with.

Is there a plug- or add-in for VS that will just 'hide' the regions? So that those that want them will see them as normal, but the people that install the add-in and view a .cs file the regions just aren't there, as if they don't exist.

I can see this might be an issue when moving code around that it might cause issues of certain methods being in or outside of the wrong region, but that might be a tradeoff the team is happy with...

like image 634
KevinT Avatar asked May 13 '09 14:05

KevinT


People also ask

How do I Collapse all regions in Visual Studio?

(Ctrl+M, Ctrl+P) - Removes all outlining information for the entire document. (Ctrl+M, Ctrl+U) - Removes the outlining information for the currently selected user-defined region. Not available in Visual Basic. (Ctrl+M, Ctrl+O) - Collapses the members of all types.

How do I hide in Visual Studio?

The #Region directive enables you to collapse and hide sections of code in Visual Basic files. The #Region directive lets you specify a block of code that you can expand or collapse when using the Visual Studio code editor. The ability to hide code selectively makes your files more manageable and easier to read.

How do you collapse rows in Visual Studio?

CTRL + M + O will collapse all.


2 Answers

I hate regions (my team loves them) and was surprised to find that nobody has written an extension to make them better. I finally wrote one myself called I Hate #Regions:

Make #regions suck less (for free):

http://visualstudiogallery.msdn.microsoft.com/0ca60d35-1e02-43b7-bf59-ac7deb9afbca

  • Auto Expand regions when a file is opened
  • Optionally prevent regions from being collapsed (but still be able to collapse other code)
  • Give the #region / #end region lines a smaller, lighter background so they are less noticeable (also an option)
  • Works in C# and VB

Region Tool Screenshot

like image 101
NotDan Avatar answered Sep 22 '22 06:09

NotDan


There are shortcut keys to deal with them:

 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 Ctrl+M, Ctrl+P  Stop outlining mode. (Ctrl+M, Ctrl+O resumes)  

See The Problem With Code Folding

like image 32
Justin Ethier Avatar answered Sep 23 '22 06:09

Justin Ethier