大纲显示Outlining

你可以选择隐藏视图中的某些代码,方法是折叠某个区域的代码,使其显示在加号 + 下面。You can choose to hide some code from view by collapsing a region of code so that it appears under a plus sign (+). 单击加号可展开折叠的区域。You expand a collapsed region by clicking the plus sign. 如果你使用的是键盘,则可选择使用 Ctrl+M+M 来进行折叠和展开。If you are a keyboard user, you can choose Ctrl+M+M to collapse and expand. 你还可以双击大纲边距(位于代码左侧)上的区域中的任意行来折叠大纲区域。You can also collapse an outlining region by double-clicking any line in the region on the outlining margin, which appears just to the left of the code. 将鼠标悬停在折叠区域时,可以看见折叠区域的内容提示。You can see the contents of a collapsed region as a tooltip when you hover over the collapsed region.

Note

本主题适用于 Visual Studio Windows 版。This topic applies to Visual Studio on Windows. 对于 Visual Studio for Mac,请参阅源编辑器 (Visual Studio for Mac)For Visual Studio for Mac, see Source editor (Visual Studio for Mac).

将鼠标悬停在边距上时也会突出显示大纲边距中的区域。Regions in the outlining margin are also highlighted when you hover over the margin with the mouse. 在某些颜色配置中,默认的突出显示颜色可能看起来很模糊。The default highlighting color may seem rather faint in some color configurations. 可在“工具” > “选项” > “环境” > “字体和颜色” > “可折叠区域”中更改此颜色。You can change it in Tools > Options > Environment > Fonts and Colors > Collapsible Region.

当处理以大纲方式显示的代码时,可以展开要处理的部分,完成后将其折叠,然后移到其他部分。When you work in outlined code, you can expand the sections you want to work on, collapse them when you are done, and then move to other sections. 如果不希望使用大纲显示方式,可以使用停止大纲显示命令删除大纲信息,但是不会影响基础代码。When you do not wish to have outlining displayed, you can use the Stop Outlining command to remove the outline information without disturbing your underlying code.

“编辑”菜单上的“撤消”和“重做”命令会影响这些操作。The Undo and Redo commands on the Edit menu affect these actions. 复制剪切粘贴和拖放操作可保留大纲信息,但是不保留可折叠区域的状态。The Copy, Cut, Paste, and drag-and-drop operations retain outlining information, but not the state of the collapsible region. 例如,如果复制处于折叠状态的区域,那么粘贴操作将把复制的文本作为展开的区域进行粘贴。For example, when you copy a region that is collapsed, the Paste operation will paste the copied text as an expanded region.

Caution

如果更改大纲显示区域,那么大纲显示可能失效。When you change an outlined region, the outlining may be lost. 例如,删除或“查找和替换”操作可能删除区域的结尾标记。For example, deletions or Find and Replace operations may erase the end of the region.

“编辑” > “大纲显示”子菜单包含以下命令。The following commands can be found on the Edit > Outlining submenu.

隐藏选定内容Hide Selection (Ctrl+M、Ctrl+H)- 折叠所选的代码块,此功能通常不可用于大纲显示,例如 if 代码块。(Ctrl+M, Ctrl+H) - Collapses a selected block of code that would not normally be available for outlining, for example an if block. 若要删除自定义区域,请使用“停止隐藏当前内容”(或使用 Ctrl+M、Ctrl+U)。To remove the custom region, use Stop Hiding Current (or Ctrl+M, Ctrl+U). 此命令不可用于 Visual Basic。Not available in Visual Basic.
切换大纲显示展开Toggle Outlining Expansion - 当游标位于嵌套的折叠部分时,反转大纲最内层部分的当前的隐藏或展开状态。- Reverses the current hidden or expanded state of the innermost outlining section when the cursor lies in a nested collapsed section.
切换所有大纲显示Toggle All Outlining (Ctrl+M、Ctrl+L)- 将所有区域设置为相同的折叠或展开状态。(Ctrl+M, Ctrl+L) - Sets all regions to the same collapsed or expanded state. 如果一些区域为展开状态,一些为折叠状态,那么将展开折叠区域。If some regions are expanded and some collapsed, then the collapsed regions are expanded.
停止大纲显示Stop Outlining (Ctrl+M、Ctrl+P)- 删除整个文档的所有大纲信息。(Ctrl+M, Ctrl+P) - Removes all outlining information for the entire document.
停止隐藏当前内容Stop Hiding Current (Ctrl+M、Ctrl+U)- 删除当前所选的用户定义的区域的大纲信息。(Ctrl+M, Ctrl+U) - Removes the outlining information for the currently selected user-defined region. 此命令不可用于 Visual Basic。Not available in Visual Basic.
折叠到定义Collapse to Definitions (Ctrl+M、Ctrl+O)- 折叠所有类型的成员。(Ctrl+M, Ctrl+O) - Collapses the members of all types.
折叠块:<逻辑边界>Collapse Block:<logical boundary> (Visual C++) 折叠包含插入点的函数中的一个区域。(Visual C++) Collapses a region in the function containing the insertion point. 例如,如果插入点在一个循环内,则隐藏此循环。For example, if the insertion point lies inside a loop, the loop is hidden.
全部折叠:<逻辑结构>Collapse All in: <logical structures> (Visual C++) 折叠函数内的所有结构。(Visual C++) Collapses all the structures inside the function.

你还可以使用 Visual Studio SDK 定义想要展开或折叠的文本区域。You can also use the Visual Studio SDK to define the text regions you want to expand or collapse. 请参阅演练:大纲显示See Walkthrough: Outlining.

请参阅See also