Ask Learn
Preview
Please sign in to use this experience.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
I think the Visio application environment is pretty impressive because of all the things you can do to customize the user interface. There are not very many apps out there that will let you add your own custom windows. Visio allows developers to do just that by enabling you to add Windows Forms as anchor bar windows. The Custom Properties window and the Pan & Zoom window are examples anchor bar windows. They can be docked, pinned, and resized on top of the Visio drawing surface.
I hope by now you have downloaded the Visio 2003 SDK. It has so many code samples for VB6, VB.NET and C#. There is even a sample that shows you how to create an anchor bar window. It also shows you how to drag and drop items from a list view control on to the Visio drawing surface as a shape. For those of you who are new to the Visio 2003 SDK, or Visio development in general, I would like to show you how to use the Code Librarian samples included with the Visio 2003 SDK.
The code samples in the Code Librarian are intended to be used in a variety of development scenarios. You can use them when creating a Visio add-in or add-on, when using the Visio drawing control, or even in standard Windows Applications that just launch and automate the Visio application environment. The Anchor Bar Usage sample would most commonly be used in a Visio add-in scenario, but for illustrative purposes, we will create a standard Windows Application:
Next, you will need to add a reference to the Visio Primary Interoperability Assembly (“PIA” for short). The Visio PIA gives you access to the COM-based Visio Object Model. To add a reference to the Visio 11 PIA:
Then you need to remove the default root namespace that is assigned when creating Visual Basic .NET projects. Note: You don’t have to do this in C# projects.
Now let’s get some code from the Code Librarian. After installing the Visio 2003 SDK, you should have a shortcut titled Microsoft Office Visio Code Librarian Viewer under the Microsoft Office Visio 2003 SDK Start Menu folder. Go ahead and start up the Code Librarian.
The Code Librarian has a tree in the top left-hand corner that allows you to navigate the different samples. Alternatively, you can use the search button on the toolbar. Find the Anchor Bar Usage sample for Microsoft Visual Basic .NET under User Interface.
The Anchor Bar Usage sample consists of two parts: a form and a module. Let’s add the module first because it’s more straightforward:
Now adding the form is a bit tricky because a form as a resource file associated with it. The resource file is not in the Code Librarian, but rather in a folder where the Code Librarian database is installed. Here’s how you add the sample Anchor Bar form.
Now, we are ready to use the sample. When we first created our Windows Application project, a default Windows Form was added. It should still be named Form1.vb. Let’s add a button to it to call our code sample:
Imports Visio = Microsoft.Office.Interop.Visio
Imports Microsoft.Samples.Visio.VBNet
Dim visioApp = New Visio.Application
DemoAnchorBar(visioApp)
Finally, we are ready to run our sample project. Go ahead and compile and run the project (F5). The Windows Form with the button control should display. When you click on this button, Visio should start. When it does, an anchor bar window should be collapsed towards the bottom of Visio. Hover over it to make it expand. It is populated with a list of shape names. Try dragging-and-dropping one of these items to the page. Voila!
This is a fairly complex sample and you should definitely step through the DemoAnchorBar function to learn how you add an anchor bar window to Visio. You should also step through the code when a drag occurs from the list view control.
We had to jump over some hurdles to set up the project. This sample in particular had some extra steps because it required a resource file. However, I hope you understand how you can take code straight from the Code Librarian and use it in your Visio development projects.
-Chris
This posting is provide “AS IS” with no warranties, and confers no rights.
Please sign in to use this experience.
Sign in