Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Adding ActiveX Controls to a Visio Solution

Using ActiveX® controls in your Microsoft® Visio® solution allows you to create a user interface that is consistent with solutions based on other Microsoft® Windows®-based applications. Because the controls are on the drawing page, the user can work freely with both controls and Visio shapes in a drawing.

In this section...

Working in Design Mode

Inserting a Control in a Drawing

Setting the Tabbing Order of Controls

Using the Visio Ambient Properties in Controls

Printing a Drawing Without its Controls

Protecting Controls from Changes

Working in Design Mode

To work with ActiveX controls in a Visio drawing, switch between design mode and run mode. In design mode, you can insert controls, move and size them, and set their properties. In run mode, you can use the controls—click a command button to run its Click event handler, for example. For other tasks, it doesn't matter whether Microsoft Visio is in design mode or run mode—all other Visio commands and tools work the same way in either mode.

The document's mode is synchronized with that of its Microsoft® Visual Basic® for Applications (VBA) project, so both the document and its project are always in the same mode. While a document is in design mode, none of its objects (including controls) issues events.

A Visio document opens in run mode by default, unless the macros in the document have been disabled. Macros are enabled or disabled depending on the security level setting for Visio and whether the VBA project has been digitally signed.

To switch to design mode, make sure the Developer toolbar is displayed. If the toolbar is not displayed, on the View menu, point to Toolbars, click Developer, and then click the Design Mode button on the Developer toolbar. The button inverts to indicate that Visio is in design mode.

Note If the security level for Visio is set to High, only signed macros from trusted sources are allowed to run; all other macros are disabled. If the security level is set to Medium (the default setting in Visio), Visio prompts the user to enable or disable macros when a document with a VBA project opens. When a document opens with macros disabled, the document opens in design mode. The user cannot switch to run mode until the document is closed and reopened with macros enabled. To set the security level for Visio, on the Tools menu, point to Macros, and then click Security. On the Security Level tab, click Low, Medium, or High.

To disable macros programmatically when a document opens, use the visOpenMacrosDisabled flag in the OpenEx method of a Documents collection.

Visio also provides policy support for security, which allows an administrator to limit the security level that a user can set. For more details, see Using Digital Certificates to Produce Trusted Solutions in http://msdn.microsoft.com/en-us/library/office/aa201749(v=office.10).aspx Chapter 15, Programming Visio with VBA.

http://msdn.microsoft.com/en-us/library/office/aa201800(v=office.10).aspx TOP

Inserting a Control in a Drawing

Before you can insert an ActiveX control in a Visio drawing, the control must be installed on your system. Certain controls can also require that you have a design license to use them in applications that you develop.

You insert a control by selecting it in the Control dialog box, which lists all of the ActiveX controls installed on your system, including those installed by other applications. Such applications typically provide a run-time license for the ActiveX controls they contain. The run-time license entitles you to use those controls in the application that contains them but not to insert the controls in applications that you develop. To insert such controls in your applications, you need a design-time license. For details, see http://msdn.microsoft.com/en-us/library/office/aa201803(v=office.10).aspx Distributing ActiveX Controls in a Visio Solution later in this chapter.

To insert an ActiveX control in a drawing

  1. On the Insert menu, click Control. Or click the Insert Control button Aa201800.bu_ActX(en-us,office.10).gif on the Developer toolbar (to show the toolbar, on the View menu, click Developer).
  1. In the Control dialog box, select a control; for example, you can select Microsoft Forms 2.0 CommandButton.

Control dialog box

Control dialog box

  1. Click OK to insert the control on the drawing page.
  1. Move and size the control as needed.

A selected control

A selected control

  1. Edit the control and set its properties as needed.

A control activated for in-place editing

A control activated for in-place editing

After you insert a control in a drawing, you can work with it in the same way as with a Visio shape. For example, you can cut or copy and paste the control, duplicate it with CTRL+drag, or make it into a master by dragging it to a stencil.

Tips for control developers

The first time you insert a control into a Visio drawing, VBA creates a "merged type library" for the control and stores it in your Temp folder in a file with an .exd file name extension. If you subsequently modify the control, delete the EXD file before attempting to insert the control again. If you receive an error message when you insert a control after modifying it, you can delete the cached EXD file to correct the problem.

If your control supports the IClassFactory2 interface, Visio uses that interface when attempting to insert a new instance of that control. Therefore, the insertion succeeds only on systems in which the control is properly licensed. If your control does not support IClassFactory2, Visio uses the IClassFactory interface to instantiate the control, and licensing is not a consideration.

http://msdn.microsoft.com/en-us/library/office/aa201800(v=office.10).aspx TOP

Setting the Tabbing Order of Controls

When Microsoft Visio is in run mode, pressing the TAB key moves the focus from one control to another on the drawing page. If you add more than one control to a drawing, you'll want the focus to move in a logical order.

The tabbing order of controls corresponds to the stacking order of the controls on the drawing page, starting with the backmost control. Initially, this is the order in which you inserted the controls in the drawing, with the most recently inserted control at the front.

To change the stacking order of controls relative to each other, use the following commands from the Order submenu on the Shape menu:

  • Bring to Front
  • Send to Back
  • Bring Forward
  • Send Backward

http://msdn.microsoft.com/en-us/library/office/aa201800(v=office.10).aspx TOP

Using the Visio Ambient Properties in Controls

If you're developing ActiveX controls for use in Microsoft Visio, you can take advantage of the ambient properties that Visio defines. A control uses an application's ambient properties to maintain a consistent appearance with other controls in a document. For example, the BackColor property specifies the color of a control's interior.

To list the ambient properties defined by Microsoft Visio

  • In the Visual Basic Editor window, right-click the Object Browser, click Show Hidden Members on the shortcut menu, and then select IVAmbients in the Classes list.

http://msdn.microsoft.com/en-us/library/office/aa201800(v=office.10).aspx TOP

Printing a Drawing Without its Controls

If you want the user to be able to print a drawing but not its controls, do one of the following:

  • Select the controls, click Behavior on the Format menu, and under Miscellaneous select Non-printing shape.
  • Assign all of the controls to the same layer and make that layer nonprinting.

For details about layers, see http://msdn.microsoft.com/en-us/library/office/aa217380(v=office.10).aspx Chapter 11, Arranging Shapes in Drawings.

http://msdn.microsoft.com/en-us/library/office/aa201800(v=office.10).aspx TOP

Protecting Controls from Changes

When you distribute a solution that contains controls, you might want users to have the ability to edit the shapes in the drawing but not the controls. You can protect controls from user changes, even in design mode, by locking the shapes and protecting the document.

To protect controls from changes

  1. Select the controls on the drawing.
  1. On the Format menu, click Protection, and then select From selection.
  1. On the View menu, click Drawing Explorer Window.
  1. In the Drawing Explorer, right-click the document, click Protect Document on the shortcut menu, and then select Shapes.
  1. Define a password in the Protect Document dialog box for added security.
Show:
© 2014 Microsoft