简体   繁体   English

在Visual Studio 2010中自动打开区域

[英]Automatically open regions in Visual Studio 2010

I'd like the regions that show up in my Visual Studio window to be expanded by default when I open a code file. 我希望在打开代码文件时默认情况下展开我的Visual Studio窗口中显示的区域。 Is this possible in VS2010, or is there an extension that will do that for me? 这在VS2010中是否可行,或者是否有扩展可以为我做到这一点?

Barring that, is my request a thing that can be written in an extension? 除此之外,我的请求是否可以在扩展中写入?

如果您希望区域关闭,请右键单击任何代码窗口,选择“ Outlining ,然后选择“ Stop Outlining

you could write a macro that calls the Visual Studio Command Edit.StopOutlining for you every time you are opening a document. 每次打开文档时,您都可以编写一个调用Visual Studio Command Edit.StopOutlining的宏。

This MSDN Page describes how to write a basic macro that handles events: http://msdn.microsoft.com/en-us/library/ee1f34as.aspx Instead of handle the WindowClosing you should handle WindowActivated . 此MSDN页面描述了如何编写处理事件的基本宏: http//msdn.microsoft.com/en-us/library/ee1f34as.aspx您应该处理WindowActivated而不是处理WindowClosing

Like this: 像这样:

Public Sub windowopen(ByVal window As EnvDTE.Window, ByVal lostFocus As EnvDTE.Window) Handles WindowEvents.WindowActivated
    DTE.ExecuteCommand("Edit.StopOutlining")
End Sub

Of course, this will call Edit.StopOutlining on every window you are opening; 当然,这会在你打开的每个窗口上调用Edit.StopOutlining ; so maybe you have to do a little bit of filtering what documenttype was activated. 所以也许你必须做一些过滤什么文件类型被激活。

There is a free Visual Studio 2010 extension which will automatically expand all regions for you: 有一个免费的Visual Studio 2010扩展 ,它将自动扩展所有区域:

Auto-Expand Visual Studio Regions 自动扩展Visual Studio区域

Please also see this related question: 另请参阅此相关问题:

How to permanently disable region-folding in Visual Studio 如何在Visual Studio中永久禁用区域折叠

For newer Visual Studio Versions (such as 2015 but it should also work for 2010) there is an extension called I hate #Regions . 对于较新的Visual Studio版本(例如2015,但它也适用于2010),有一个名为I hate #Regions的扩展。 You can download and install it via Tools > Extensions and Updates > Online . 您可以通过工具>扩展和更新>在线下载和安装它。 It auto expands all regions and lowers the font size of region tags. 它会自动扩展所有区域并降低区域标签的字体大小。 Hope it helps. 希望能帮助到你。

To create a macro that expands all regions for C# files only do the following. 要创建扩展C#文件的所有区域的宏,请执行以下操作。

  1. Open the Visual Studio Studio Macros window from Tools > Macros > Macros IDE... 从工具>宏>宏IDE中打开Visual Studio Studio宏窗口...

  2. In the EnvironmentEvents vb file in Project Explorer (if there isn't one then create a new module and it will appear) add the following code after the automatically generated code region 在Project Explorer中的EnvironmentEvents vb文件中(如果没有,然后创建一个新模块,它将出现)在自动生成的代码区域之后添加以下代码

     Private Sub WindowEvents_WindowActivated(ByVal GotFocus As EnvDTE.Window, ByVal LostFocus As EnvDTE.Window) Handles WindowEvents.WindowActivated If GotFocus.Document.FullName.EndsWith(".cs") Then DTE.ExecuteCommand("Edit.StopOutlining") End If 

    End Sub 结束子

  3. Save and Build the project 保存并构建项目

If you need some more help with macros then read this msdn page for more information. 如果您需要更多有关宏的帮助,请阅读此msdn页面以获取更多信息。

There is one issue with this macro that I'm currently working on is that if you click any file in the solution explorer VS will automatically open it. 我正在处理的这个宏存在一个问题,即如果您单击解决方案资源管理器中的任何文件,VS将自动打开它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM