Hiding the regions in Visual Studio

后端 未结 7 464
-上瘾入骨i
-上瘾入骨i 2020-12-08 10:19

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# gu

7条回答
  •  醉梦人生
    2020-12-08 11:21

    For VS 2008 users, you can stop outlining and restart it programatically (via a macro). I found this code at http://weblogs.asp.net/rweigelt/archive/2003/07/06/9741.aspx

    Imports EnvDTE
    
    ' Expands all regions in the current document    
    Sub ExpandAllRegions()        
        DTE.ExecuteCommand("Edit.StopOutlining")        
        DTE.ExecuteCommand("Edit.StartAutomaticOutlining")    
    End Sub
    

    The above works for C# IDE; for some reason, VB's IDE doesn't remove outlining with regions when explicitly told to. Hope this helps!

    -- appended edit:

    Here's one that does work for Visual Basic .NET in Visual Studio 2008. It's a bit of brute force, but the idea is to comment all of the #region markers, expanding the outline. The next step uncomments them, returning them to their original state (not strictly true... could have rogue uses of #region in other parts of the code). This code doesn't return the Find & Replace dialog back to it's original state, either. With those caveats, this is the macro module that will perform this chore:

    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports EnvDTE90
    Imports System.Diagnostics
    
    Public Module MacroMod01
        Sub ExpandAllRegions()
        ' comment out all #region occurances
            DTE.ExecuteCommand("Edit.Replace")
            DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
            DTE.Find.FindWhat = "#region"
            DTE.Find.ReplaceWith = "'#region"
            DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
            DTE.Find.MatchCase = False
            DTE.Find.MatchWholeWord = False
            DTE.Find.MatchInHiddenText = True
            DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
            DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
            DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
            DTE.Find.Execute()
    
        ' uncomment all #region occurances
            DTE.ExecuteCommand("Edit.Replace")
            DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
            DTE.Find.FindWhat = "'#region"
            DTE.Find.ReplaceWith = "#region"
            DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
            DTE.Find.MatchCase = False
            DTE.Find.MatchWholeWord = False
            DTE.Find.MatchInHiddenText = True
            DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
            DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
            DTE.Find.Action = vsFindAction.vsFindActionReplaceAll
            DTE.Find.Execute()
    
        'close the find 'n replace dialog
            DTE.Windows.Item("{CF2DDC32-8CAD-11D2-9302-005345000000}").Close()  
    
        End Sub
    
    End Module
    

    There may be a few other methods to accomplish this for VB in VS2008. I'll post as I find them.

提交回复
热议问题