Closing the Visio Shape Search Window Programmatically

Started by Visio Guy, June 07, 2008, 01:55:02 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Visio Guy

In a recent post, Orbital asked how to turn off the Shape Search Window:

Quote from: 0rbital on June 06, 2008, 11:25:41 PM

...one more quick question. 

I don't want the Shapes Search and window on the left of the drawing displayed. 

How do I get rid of that?


There seem to be two answers to this question, involving the methods: win.Close and win.Visible.


Close Down the Whole Docked Stencil Area

If we call the Close method on the window, it closes the whole docked stencil area!

We lose the Shape Search window, plus any docked stencils. This might be too extreme in some cases, others might rejoice.

Here's how we close the window using code:


  Call Visio.ActiveWindow.Windows.ItemFromID(visWinIDShapeSearch).Close


Note: the Shape Search window is a sub-window of the drawing window, i.e.: Window.Windows(item), so to speak. We identify the it using the Visio enumeration: Visio.VisWinTypes.visWinIDShapeSearch.

Also, f the user clicks View > Shapes Window, then the Shape Search window re-appears, along with any stencils that might have been open. Everything was just temporarily hidden.


Close Down the Just The Shape Search Control

Now, if we just want to close the Shape Search portion at the top of the docked stencil area, then we can turn of visibility:


  Visio.ActiveWindow.Windows.ItemFromID(visWinIDShapeSearch).Visible = False


The docked stencil area remains, just the little Shape Search text field disappears. Nice!

This all worked just fine in VBA, and I assume it will work for VB.NET and the Visio ActiveX drawing control, but it's Saturday and I am too lazy to double-check, so let me know if anything is aberrant.


Close Down All Sub-windows

For folks using the Visio ActiveX Drawing Control, I often add this little procedure to my code, and call it when I open a document (using the SRC property...)

It closes all "anchor bar" windows so that you just see the drawing. Anchor bar windows can be Shape Search, Shape Data, Size & Position, Document Explorer, docked stencils, etc.



    '// VB.NET code to close all of the anchor windows in the Visio
    '// ActiveX Drawing Control.
    '//
    '// Close all of the drawing window's anchor windows, like the dreaded
    '// ShapeSearch window, custom properties, and others.
    Private Sub m_closeAnchorWindows()

        '// Close all of the anchor bar windows:
        '// Note: Me.VisActiveXControl is a Visio ActiveX Drawing control
        '//         on the form to which 'Me' refers.
        For Each win As Visio.Window In Me.VisActiveXControl.Window.Windows
            If win.Visible Then win.Close()
        Next

    End Sub


For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

0rbital

You created this as I posted my own answer on the OP:


Just for reference if you want to show the pan and zoom, close the shape search window, and close shapes window during the form load in C# you would do this:

            // show pan and zoom window
            Visio.Window winPanZoom = axDrawingControl1.Window.Windows.get_ItemFromID((int)Visio.VisWinTypes.visWinIDPanZoom);           
            winPanZoom.Visible = true;
           
            //get rid of shapes search window
            Visio.Window winShapeSearch = axDrawingControl1.Window.Windows.get_ItemFromID((int)Visio.VisWinTypes.visWinIDShapeSearch);
            winShapeSearch.Visible = false;

            //get rid of shapes window
            vsoApp.DoCmd(1669);

0rbital

Quote from: 0rbital on June 07, 2008, 01:58:42 PM
You created this as I posted my own answer on the OP:


Just for reference if you want to show the pan and zoom, close the shape search window, and close shapes window during the form load in C# you would do this:

            // show pan and zoom window
            Visio.Window winPanZoom = axDrawingControl1.Window.Windows.get_ItemFromID((int)Visio.VisWinTypes.visWinIDPanZoom);           
            winPanZoom.Visible = true;
           
            //get rid of shapes search window
            Visio.Window winShapeSearch = axDrawingControl1.Window.Windows.get_ItemFromID((int)Visio.VisWinTypes.visWinIDShapeSearch);
            winShapeSearch.Visible = false;

            //get rid of shapes window
            vsoApp.DoCmd(1669);

I found a strange issue with the DoCmd(1669)  on my development box it always gets rid of the shapes window.  when I put it on the tool the application is going to run on to test it the shapes window was there minus all the shapes so the user couldn't grab any shapes but the docked window was still present.  So I took the example above to close the window and did it in C# here is the code for that:

            Visio.Window winShapeSearch = axDrawingControl1.Window.Windows.get_ItemFromID((int)Visio.VisWinTypes.visWinIDShapeSearch);
            winShapeSearch.Close();

Now if you want the user to be able to bring the window back up for any reason you can call vsoApp.DoCmd(1669); and the shapes window will reappear docked where it was when you closed it.

Visio Guy

The potential weakness with DOCMD(1669) is that it is a toggle.

So it reverses the visibility of the Shapes window, and that means you don't know (in code) if you are turning it on or off.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Visio Guy

New findings about closing anchor windows, and specifically the Shapes window.

If you are programming in VB.NET, it helps to call Application.DoEvents() when closing anchor windows.

I was just working with a client, and the loop below did NOT close the Shapes window, but did close all the other anchor bar windows, like Shape Data, Pan & Zoom, etc.


'winActive is for example Visio.ActiveWindow...

For Each win As Visio.Window In winActive.Windows
  win.Visible = False
Next


When we added Application.DoEvents() then the Shapes window went away.



'winActive is for example Visio.ActiveWindow...

For Each win As Visio.Window In winActive.Windows
  win.Visible = False
  Application.DoEvents()
Next


Hope this helps somebody out.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

vojo

Note that this is order sensitive...see my thread from about a month or so ago
In essence if you dont unwind it the same order you wound it....it wont reliable close or open.