不在资源视图中时隐藏属性/工具箱窗格?

发布于 2024-07-27 00:14:13 字数 141 浏览 4 评论 0原文

每次我在 Visual Studio (2005) 中查看表单或对话框时,“属性”和“工具箱”窗格都会显示在屏幕右侧。 这是很好的,因为它们对于操作对话框很有用。

然而,一旦我切换回源代码,这些窗格就会妨碍......有没有办法让它们自动消失?

Every time I view a form or dialog in Visual Studio (2005) the Properties and Toolbox panes show up on the right side of my screen. That's good to have because they are useful for manipulating dialogs.

However once I switch back to source code these panes just get in the way... is there a way to get them to go away automatically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

狼亦尘 2024-08-03 00:14:13

我最近在 VS2010 中使用一个宏做了一些事情,该宏在 asp.net MVC3 视图中从代码视图来回切换到设计视图时显示和隐藏“工具”面板。 我认为它可以很容易地适应你的情况。

该内容位于 VS Macro IDE 中预生成内容之后的 EnvironmentEvents 类文件中。

<System.ContextStaticAttribute()> Public WithEvents CommandEvents As EnvDTE.CommandEvents


  Public Sub DTEEvents_OnMacrosRuntimeReset() Handles _
  DTEEvents.OnMacrosRuntimeReset
        CommandEvents = DTE.Events.CommandEvents
    End Sub

    Private Sub DTEEvents_OnStartupComplete() Handles _
        DTEEvents.OnStartupComplete
        CommandEvents = DTE.Events.CommandEvents
    End Sub

    Public Sub CommandEvents_AfterExecute( _
    ByVal Guid As String, _
    ByVal ID As Integer, _
    ByVal CustomIn As Object, _
    ByVal CustomOut As Object) _
    Handles CommandEvents.AfterExecute

        If DTE.Commands.Item(Guid, ID).Name = "View.ViewDesigner" Then
            DTE.ExecuteCommand("View.Toolbox")
        End If

        If DTE.Commands.Item(Guid, ID).Name = "View.ViewMarkup" Then
            DTE.Windows.Item(Constants.vsWindowKindToolbox).Close()
        End If

    End Sub

使用事件指南而不是 if 语句可能会更好地优化它。 当您使用热键切换视图以及视图菜单(但不是上下文菜单)时,它会起作用。

I've done something recently in VS2010 using a macro that shows and hides the Tools panel when switching back and forth from code to design view in asp.net MVC3 views. It could be easily adapted to do the same for your situation I think.

This goes in the EnvironmentEvents class file in in the VS Macro IDE after the pre-generated content.

<System.ContextStaticAttribute()> Public WithEvents CommandEvents As EnvDTE.CommandEvents


  Public Sub DTEEvents_OnMacrosRuntimeReset() Handles _
  DTEEvents.OnMacrosRuntimeReset
        CommandEvents = DTE.Events.CommandEvents
    End Sub

    Private Sub DTEEvents_OnStartupComplete() Handles _
        DTEEvents.OnStartupComplete
        CommandEvents = DTE.Events.CommandEvents
    End Sub

    Public Sub CommandEvents_AfterExecute( _
    ByVal Guid As String, _
    ByVal ID As Integer, _
    ByVal CustomIn As Object, _
    ByVal CustomOut As Object) _
    Handles CommandEvents.AfterExecute

        If DTE.Commands.Item(Guid, ID).Name = "View.ViewDesigner" Then
            DTE.ExecuteCommand("View.Toolbox")
        End If

        If DTE.Commands.Item(Guid, ID).Name = "View.ViewMarkup" Then
            DTE.Windows.Item(Constants.vsWindowKindToolbox).Close()
        End If

    End Sub

It could probably be better optimized using the guids of the event rather than the if statements. It works when you use the hot keys for switching views as well as the view menu, but not the context menu.

难忘№最初的完美 2024-08-03 00:14:13

对于 vs2015:

  1. 菜单 > 工具> 扩展和更新
  2. 安装“Visual Commander”。 (现在您有名为“VCmd”的新菜单)
  3. 菜单> “VCmd”> 扩展...(您将在右侧看到扩展窗格)
  4. 按扩展窗格中的添加按钮。 (将打开新选项卡窗口。)
  5. 输入扩展名。
  6. 选择语言为 C#。
  7. 粘贴以下代码:
  8. 按“保存”。 然后按编译。 然后按安装

using EnvDTE;
using EnvDTE80;

public class E : VisualCommanderExt.IExtension
{
    private EnvDTE80.DTE2 DTE;
    private EnvDTE.WindowEvents windowEvents;

    public void SetSite(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) {
        this.DTE = DTE;
        DTE.Events.WindowEvents.WindowActivated += OnWindowActivated;   
    }

    public void Close() {
        // i read somewhere this has to be done on close. 
        // but it gives gives me error on every IDE close. so i commented it .
        //DTE.Events.WindowEvents.WindowActivated -= OnWindowActivated;
    }

    private void OnWindowActivated(Window gotFocus, Window lostFocus) {
            HidePropertiesWindowInCodeOrTextView(gotFocus );
    }

    public void HidePropertiesWindowInCodeOrTextView(Window gotFocus ) {
           if (gotFocus.Document == null) return;
              var pwin = DTE.Windows.Item(Constants.vsWindowKindProperties);
              pwin.AutoHides  = !gotFocus.Caption.EndsWith(" [Design]") ;
    }
}

for vs2015:

  1. Menu > Tools > Extensions and Updates
  2. install "Visual Commander". (Now you have New Menu called "VCmd")
  3. Menu > "VCmd" > Extensions ... (You will see an Extensions Pane At Right)
  4. Press Add Button at the Extensions Pane. (New tab Wİndow will open.)
  5. write a name for extention.
  6. select language as C#.
  7. paste the code below:
  8. Press Save. Then Press Compile. Then Press Install

using EnvDTE;
using EnvDTE80;

public class E : VisualCommanderExt.IExtension
{
    private EnvDTE80.DTE2 DTE;
    private EnvDTE.WindowEvents windowEvents;

    public void SetSite(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) {
        this.DTE = DTE;
        DTE.Events.WindowEvents.WindowActivated += OnWindowActivated;   
    }

    public void Close() {
        // i read somewhere this has to be done on close. 
        // but it gives gives me error on every IDE close. so i commented it .
        //DTE.Events.WindowEvents.WindowActivated -= OnWindowActivated;
    }

    private void OnWindowActivated(Window gotFocus, Window lostFocus) {
            HidePropertiesWindowInCodeOrTextView(gotFocus );
    }

    public void HidePropertiesWindowInCodeOrTextView(Window gotFocus ) {
           if (gotFocus.Document == null) return;
              var pwin = DTE.Windows.Item(Constants.vsWindowKindProperties);
              pwin.AutoHides  = !gotFocus.Caption.EndsWith(" [Design]") ;
    }
}
撩心不撩汉 2024-08-03 00:14:13

我没有放弃屏幕右侧的空间,而是将属性和工具箱窗格拖到托管解决方案资源管理器和类视图等的左侧框架。我宁愿在屏幕上放置一个多功能框屏幕的一侧比将代码包围起来要好。 如果您同时需要它们,则可以将工具箱放在解决方案资源管理器窗格中,然后将属性窗格堆叠在解决方案资源管理器下方,这样可以始终与工具箱一起查看一些属性。

我知道这并不是您正在寻找的答案,但这是一种保持屏幕空间可用于代码而不干扰自动隐藏的不同方式(我发现自动隐藏实际上是一种烦恼而不是帮助。)

Rather than give up the space on the right side of the screen, I dragged my properties and toolbox panes over to the left-side frame that hosts the solution explorer and class view, etc. I'd rather have one multi-purpose box on one side of the screen than to have the code surrounded. If you need them both, you can put the toolbox in the solution explorer pane, then stack the properties pane beneath the solution explorer, which keeps a few properties in view at all times along with the toolbox.

I know it's not quite the answer you were looking for, but it's a different way of keeping that screen real estate available for code without messing with auto-hide (I find auto-hide to be really an annoyance more than a help.)

记忆消瘦 2024-08-03 00:14:13

对于 vs2019:

我改进了 bh_earth0 的解决方案。 现在,当您跳转到代码时,它会保存属性和工具箱的可见性状态。 当设计选项卡被激活时,它会加载窗格的先前状态。

  1. 菜单> 扩展> 管理扩展

  2. 查找并安装“Visual Commander”。 (现在您有名为“VCmd”的新菜单)

  3. 菜单> “VCmd”> 扩展...(您将在右侧看到扩展窗格)

  4. 按扩展窗格中的添加按钮。 (新选项卡窗口将打开。)

  5. 为扩展写入名称(例如自动隐藏)。

  6. 选择语言为 C#。

  7. 复制并粘贴以下代码:

  8. 按“保存”。 然后按编译。 然后按安装

  9. 重新启动 Visual Studio 并享受:-)

    使用 EnvDTE; 
      使用EnvDTE80; 
    
      公共类E:VisualCommanderExt.IExtension 
      { 
          私有 EnvDTE80.DTE2 DTE; 
          私有EnvDTE.WindowEvents windowEvents; 
    
          私有 bool bPropWinVisible = false; 
          私有 bool bToolWinVisible = false; 
    
          公共无效SetSite(EnvDTE80.DTE2 DTE,Microsoft.VisualStudio.Shell.Package包){ 
              这.DTE = DTE; 
              DTE.Events.WindowEvents.WindowActivated += OnWindowActivated;    
          } 
    
          公共无效关闭(){ 
          } 
    
          私有无效OnWindowActivated(窗口获得焦点,窗口丢失焦点){ 
              if (gotFocus.Document == null) 返回; 
              if (lostFocus.Document == null) 返回; 
    
              var pwin = DTE.Windows.Item(Constants.vsWindowKindProperties); 
              var twin = DTE.Windows.Item(Constants.vsWindowKindToolbox); 
    
              if(gotFocus.Caption.EndsWith(".cs [设计]") &&lostFocus.Caption.EndsWith(".cs") ) { 
                  pwin.AutoHides = bPropWinVisible; 
                  twin.AutoHides = bToolWinVisible; 
              } 
              else if(gotFocus.Caption.EndsWith(".cs") &&lostFocus.Caption.EndsWith(".cs [设计]")) { 
                  bPropWinVisible = pwin.AutoHides; 
                  bToolWinVisible = twin.AutoHides; 
                  pwin.AutoHides = true; 
                  twin.AutoHides = true; 
              } 
          } 
      } 
      

For vs2019:

I improve bh_earth0's solution. Now it saves visibility states of Properties and ToolBox when you jump to code. And when design tab is activated it loads previous state of panes.

  1. Menu > Extensions > Manage Extensions

  2. Find and install "Visual Commander". (Now you have New Menu called "VCmd")

  3. Menu > "VCmd" > Extensions ... (You will see an Extensions Pane At Right)

  4. Press Add Button at the Extensions Pane. (New tab Wİndow will open.)

  5. write a name for extention (e.g. AutoHide).

  6. select language as C#.

  7. copy and paste the code below:

  8. Press Save. Then Press Compile. Then Press Install

  9. Restart the Visual Studio and enjoy :-)

    using EnvDTE;
    using EnvDTE80;
    
    public class E : VisualCommanderExt.IExtension
    {
        private EnvDTE80.DTE2 DTE;
        private EnvDTE.WindowEvents windowEvents;
    
        private bool bPropWinVisible = false;
        private bool bToolWinVisible = false;
    
        public void SetSite(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) {
            this.DTE = DTE;
            DTE.Events.WindowEvents.WindowActivated += OnWindowActivated;   
        }
    
        public void Close() {
        }
    
        private void OnWindowActivated(Window gotFocus, Window lostFocus) {
            if (gotFocus.Document == null) return;
            if (lostFocus.Document == null) return;
    
            var pwin = DTE.Windows.Item(Constants.vsWindowKindProperties);
            var twin = DTE.Windows.Item(Constants.vsWindowKindToolbox);
    
            if(gotFocus.Caption.EndsWith(".cs [Design]") && lostFocus.Caption.EndsWith(".cs") ) {
                pwin.AutoHides = bPropWinVisible;
                twin.AutoHides = bToolWinVisible;
            }
            else if(gotFocus.Caption.EndsWith(".cs") && lostFocus.Caption.EndsWith(".cs [Design]")) {
                bPropWinVisible = pwin.AutoHides;
                bToolWinVisible = twin.AutoHides;
                pwin.AutoHides = true;
                twin.AutoHides = true;
            }
        }
    }
    
冷…雨湿花 2024-08-03 00:14:13

如果单击这些工具窗口上的“固定”图标,您可以切换窗口是始终保持打开状态,还是仅在鼠标靠近它们时保持打开状态。 当然,有时我的鼠标会朝那个方向移动,当我不希望它们弹出时,它们会弹出,但这就是生活......

If you click the 'pin' icon on those tool windows, you can toggle whether the windows stay open all the time, or only when the mouse is near them. Of course, sometimes my mouse strays over in that direction and they pop out when I don't want them to, but such is life...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文