C# 如何在 Visual Studio 2008 中永久禁用区域折叠
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/115694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to permanently disable region-folding in Visual Studio 2008
提问by Steve Cooper
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 #regions
or function bodies.
有人知道如何在 Visual Studio 2008 中关闭代码折叠吗?我的一些同事喜欢它,但我个人总是希望看到所有的代码,从不希望代码折叠起来。我想要一个设置,这意味着我的 Visual Studio 副本永远不会折叠#regions
或函数体。
采纳答案by Greg
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".
转到工具-> 选项菜单。转到文本编辑器-> C#-> 高级。取消选中“打开文件时进入大纲模式”。
That will disable all outlining, including regions, for all c# code files.
这将禁用所有 c# 代码文件的所有大纲,包括区域。
回答by MarcE
Options / Text Editor / C# / Advanced / Enter outlining mode when files open
选项/文本编辑器/C#/高级/打开文件时进入大纲模式
回答by Lou Franco
It's not permanent, but the keystrokes Ctrl-M Ctrl-L expand the regions in a file
它不是永久性的,但击键 Ctrl-M Ctrl-L 扩展文件中的区域
回答by jules
Also, a quick way to toggle expand/collapse of all regions is: CTRL + M + L
此外,切换所有区域的展开/折叠的快速方法是:CTRL + M + L
回答by Dusda
You can also disable region-wrapping on generated code (like when you use the Visual Studio shortcut to auto-implement an interface).
您还可以在生成的代码上禁用区域包装(例如当您使用 Visual Studio 快捷方式自动实现接口时)。
回答by JMD
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.
我在一个相关但不重复的线程中发布了一个答案,可能会帮助这里的一些人。我详细说明了如何通过注释掉 #region 和 #endregion 指令以及用于重新激活它们的同伴来创建将停用单个单元的 #regions 的宏。停用 #regions 后,Ctrl+M+O/折叠到定义功能完全符合我的要求。我希望这对我以外的人有用。
回答by Czarek Tomczak
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).
此选项似乎仅在 C# 中可用,而在 C/C++ (Visual Studio 2005) 中不可用。要在 C/C++ 文件中禁用大纲,您需要通过将大纲颜色更改为编辑器的背景颜色来制作一个技巧。为此,请转到工具 > 选项 > 环境 > 字体和颜色 > 可折叠文本 > 将“项目前景”颜色更改为白色(或任何您的背景颜色)。
回答by NotDan
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.
接受的答案会关闭所有代码折叠。如果您想禁用 #region 折叠但折叠注释、循环、方法等,我编写了一个插件来为您执行此操作。
Make #regions suck less (for free):
让 #regions 少吸(免费):
http://visualstudiogallery.msdn.microsoft.com/0ca60d35-1e02-43b7-bf59-ac7deb9afbca
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 / #end 区域线一个更小、更亮的背景,这样它们就不那么明显了(也是一个选项)
- 适用于 C# 和 VB(但仅适用于 VS 2010/2012,2008 不支持)
回答by xks
i resolved the problem for me with an environmentevent:
我通过环境事件为我解决了这个问题:
- start macroeditor (alt+f11)
- open macroproject / EnvironmentEvents
- paste the follwing code:
- 启动宏编辑器 (alt+f11)
- 打开宏项目/环境事件
- 粘贴以下代码:
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
问候托比