Hide Properties/Toolbox Pane when not in Resource View?

三世轮回 提交于 2019-12-30 05:48:08

问题


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?


回答1:


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.




回答2:


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]") ;
    }
}



回答3:


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.)




回答4:


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...



来源:https://stackoverflow.com/questions/1139710/hide-properties-toolbox-pane-when-not-in-resource-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!