theycallmemorty
theycallmemorty

Reputation: 12962

Hide Properties/Toolbox Pane when not in Resource View?

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?

Upvotes: 15

Views: 4109

Answers (5)

bh_earth0
bh_earth0

Reputation: 2818

edit_2024: my latest answer here: https://stackoverflow.com/a/47554393/3137362

supported VS: vs2015, vs2017, vs2019 .

supported Projects: Winforms , WPF , Xamarin.Android .


old-answer:

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

Upvotes: 2

Fano99
Fano99

Reputation: 31

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;
            }
        }
    }
    

Upvotes: 0

Graham Conzett
Graham Conzett

Reputation: 8454

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.

Upvotes: 4

John Deters
John Deters

Reputation: 4391

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

Upvotes: 0

Nick Meyer
Nick Meyer

Reputation: 40272

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

Upvotes: -1

Related Questions