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.
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.
Have you tried Tools\Options\Text Editor\C#\Advanced and check the "Enter outlining mode" when files open?
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
For the record, I found unchecking the 'Enter Outlining Mode' option would disable all outlining, which was undesirable.
I did find this extension though: https://visualstudiogallery.msdn.microsoft.com/0ca60d35-1e02-43b7-bf59-ac7deb9afbca , the "I Hate #Regions" extension. Available for VS2010-2015, and so far seems to work as advertised.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.