visual-studio 如何在 Visual Studio 2008 中折叠选定的代码块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1626036/
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 do I collapse selected chunks of code in Visual Studio 2008?
提问by Faken
In Visual Studio 2008: Is there a way for me to customly collapse bits of code similar to like how I can automatically collapse chunks of comments?
在 Visual Studio 2008 中:有没有办法让我自定义折叠代码位,类似于如何自动折叠评论块?
回答by KeatsPeeks
Your piece of code needs to be a block surrounded by, as desired:
根据需要,您的代码段需要是一个由以下内容包围的块:
- braces
#regionand#endregionin C##pragma regionand#pragma endregionin C/C++
- 大括号
#region而#endregion在C##pragma region和#pragma endregion在C / C ++
If you can't collapse statement blocks, you need to enable this feature :
如果不能折叠语句块,则需要启用此功能:
Tools -> Options -> Text Editor -> C/C++ -> Formatting -> check everything in "outlining"
工具 -> 选项 -> 文本编辑器 -> C/C++ -> 格式 -> 检查“大纲”中的所有内容
(In Visual Studio 2013 it's Tools -> Options -> Text Editor -> C/C++ -> View)
(在 Visual Studio 2013 中,它是工具 -> 选项 -> 文本编辑器 -> C/C++ -> 视图)
Then, reopen the source file to reload outlining.
然后,重新打开源文件以重新加载大纲。
回答by epotter
TheSam is right, you can create collapsible chunks with the #pragma region and #pragma endregion statements.
TheSam 是对的,您可以使用 #pragma region 和 #pragma endregion 语句创建可折叠的块。
Here is a sample:
这是一个示例:
int main(array<System::String> args)
{
Console::WriteLine(L"This");
Console::WriteLine(L"is");
Console::WriteLine(L"a");
#pragma region
Console::WriteLine(L"pragma");
Console::WriteLine(L"region");
#pragma endregion
Console::WriteLine(L"test.");
return 0;
}
In the above sample, everything between the samples can be collapsed.
在上面的示例中,示例之间的所有内容都可以折叠。
You can also specify what text is displayed when it is collapsed. You can do that like this:
您还可以指定折叠时显示的文本。你可以这样做:
#pragma region The displayed text
That would obviously display "The displayed text" when the region was collapsed.
当区域折叠时,这显然会显示“显示的文本”。
回答by Martin Sansone - MiOEE
This extension is made for the job in Visual Studio: http://visualstudiogallery.msdn.microsoft.com/4d7e74d7-3d71-4ee5-9ac8-04b76e411ea8
此扩展是为 Visual Studio 中的工作制作的:http: //visualstudiogallery.msdn.microsoft.com/4d7e74d7-3d71-4ee5-9ac8-04b76e411ea8

