How to configure Visual Studio to collapse all regions by default?
Solution 1
As a last resort if you can't get it to work with settings, you can also write a macro to do this. Check out this link for an example on this.
Here is the main information from the link:
You can open the Macro IDE by going to Tools->Macros->Macros IDE. There should be a module called EnvironmentEvents in project MyMacros. This code should be added to the EnvironmentEvents Module:
Private opened As Boolean
Private Sub WindowEvents_WindowActivated(ByVal GotFocus As EnvDTE.Window, ByVal LostFocus As EnvDTE.Window) Handles WindowEvents.WindowActivated
If GotFocus.Document Is Nothing Then
Return
End If
If GotFocus.Document.FullName.EndsWith(".cs") And opened = True Then
DTE.ExecuteCommand("Edit.CollapsetoDefinitions")
End If
opened = False
End Sub
Private Sub DocumentEvents_DocumentOpened(ByVal Document As EnvDTE.Document) Handles DocumentEvents.DocumentOpened
opened = True
End Sub
Solution 2
This is possible. Go to the Tools menu, then select options.
Text Editor
\ C#
\ Advanced
The option is called "Enter outlining mode when files open." When outlining mode is enabled, your regions are collapsed by default.
Solution 3
Have you tried Tools\Options\Text Editor\C#\Advanced and check the "Enter outlining mode" when files open?

Ivan
Updated on July 04, 2022Comments
-
Ivan 6 months
When I open a code file in a new code window, I press Ctrl+M,O to collapse everything there. As far as I know this can be done by default, without need to press anything every time. I think I did it once, but can't remember where was this option located.