How to permanently disable region-folding in Visual Studio 2008

C#Visual Studio-2008Text EditorOutlining

C# Problem Overview


Anyone know how to turn off code folding in visual studio 2008? Some of my colleagues love it, but I personally always want to see all the code, and never want code folded out of sight. I'd like a setting that means my copy of Visual Studio never folds #regionsor function bodies.

C# Solutions


Solution 1 - C#

Edit: I recommend this other answer

Go to the Tools->Options menu. Go to Text Editor->C#->Advanced. Uncheck "Enter outlining mode when files open".

That will disable all outlining, including regions, for all c# code files.

Solution 2 - C#

The accepted answer turns off ALL code folding. If you want to disable #region folding but collapse comments, loops, methods, etc I wrote a plugin that does this for you.

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 (but only in VS 2010/2012, not supported for 2008)

Region Tool Screenshot

Solution 3 - C#

You can also disable region-wrapping on generated code (like when you use the Visual Studio shortcut to auto-implement an interface).

alt text

Solution 4 - C#

Options / Text Editor / C# / Advanced / Enter outlining mode when files open

Solution 5 - C#

It's not permanent, but the keystrokes Ctrl-M Ctrl-L expand the regions in a file

Solution 6 - C#

Also, a quick way to toggle expand/collapse of all regions is: CTRL + M + L

Solution 7 - C#

I've posted an answer in a related-but-not-duplicate thread that may help some people here. I detailed how to create macros that will deactivate a single unit's #regions by commenting out the #region and #endregion directives, with a companion for reactivating them. With the #regions deactivated the Ctrl+M+O / Collapse to Definitions function does exactly what I want it to. I hope this is useful for someone beside myself.

https://stackoverflow.com/questions/225413/shortcut-to-collapse-to-definitions-except-regions/1805597#1805597

Solution 8 - C#

This option seem to be available only in C# and not in C/C++ (Visual Studio 2005). To disable outlining in C/C++ files you need to make a trick by changing the outlining color to editor's background color. To do this go to Tools > Options > Environment > Fonts and Colors > Collapsible Text > Change "Item Foreground" color to White (or whatever your background color is).

Solution 9 - C#

i resolved the problem for me with an environmentevent:

  1. start macroeditor (alt+f11)
  2. open macroproject / EnvironmentEvents
  3. paste the follwing code:


Private Sub DocumentEvents_DocumentOpened(ByVal Document As EnvDTE.Document) Handles DocumentEvents.DocumentOpened
If (Not Document Is Nothing) Then
If (Document.FullName.ToLower().EndsWith(".cs")) Then
Try
DTE.ExecuteCommand("Edit.ExpandAllOutlining")
Catch ex As Exception
End Try
End If
End If
End Sub



Private Sub WindowEvents_WindowActivated(ByVal GotFocus As EnvDTE.Window, ByVal LostFocus As EnvDTE.Window) Handles WindowEvents.WindowActivated
    If (Not GotFocus Is Nothing) Then
        If (Not GotFocus.Document Is Nothing) Then
            If (GotFocus.Document.FullName.ToLower().EndsWith(".cs")) Then
                Try
                    DTE.ExecuteCommand("Edit.ExpandAllOutlining")
                Catch ex As Exception
                End Try
            End If
        End If
    End If
End Sub


Greetings Tobi

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSteve CooperView Question on Stackoverflow
Solution 1 - C#GregView Answer on Stackoverflow
Solution 2 - C#NotDanView Answer on Stackoverflow
Solution 3 - C#DusdaView Answer on Stackoverflow
Solution 4 - C#MarcEView Answer on Stackoverflow
Solution 5 - C#Lou FrancoView Answer on Stackoverflow
Solution 6 - C#julesView Answer on Stackoverflow
Solution 7 - C#JMDView Answer on Stackoverflow
Solution 8 - C#Czarek TomczakView Answer on Stackoverflow
Solution 9 - C#xksView Answer on Stackoverflow