How to configure Visual Studio to collapse all regions by default?

混江龙づ霸主 提交于 2019-12-29 04:34:09

问题


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.


回答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



回答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.




回答3:


Have you tried Tools\Options\Text Editor\C#\Advanced and check the "Enter outlining mode" when files open?




回答4:


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.



来源:https://stackoverflow.com/questions/6312255/how-to-configure-visual-studio-to-collapse-all-regions-by-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!