Adding ActiveX Controls to a Visio Solution

3 4

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.

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


Ifthe 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 Chapter 15, Programming Visio with VBA.

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 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 bu_ActX.GIF on the Developer toolbar (to show the toolbar, on the View menu, click Developer).
  2. In the Control dialog box, select a control; for example, you can select Microsoft Forms 2.0 CommandButton.
  3. Figure 24-1.  <b>Control</b> dialog box.

    Figure 24-1 Control dialog box.

  4. Click OK to insert the control on the drawing page.
  5. Move and size the control as needed.
  6. A selected control has green selection handles, just like a selected shape, and you move and size the control the same way.

    figure 24-2. a selected control.

    Figure 24-2 A selected control.

  7. Edit the control and set its properties as needed.
  8. To edit a control, double-click it. A control activated for in-place editing in this way looks the same in Microsoft Visio as in any ActiveX container. To set a control's properties or write code for the control, right-click the control and point to the name of the control object on the shortcut menu. You can then select a command that allows you to modify the control using the Visual Basic Editor.

    figure 24-3. a control activated for in-place editing.

    Figure 24-3 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.

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

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.
  • Ambient properties are read-only.

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 Chapter 11, Arranging Shapes in Drawings.

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.
  2. On the Format menu, click Protection, and then select From selection.
  3. On the View menu, click Drawing Explorer Window.
  4. In the Drawing Explorer, right-click the document, click Protect Document on the shortcut menu, and then select Shapes.
  5. Define a password in the Protect Document dialog box for added security.
  6. The user will be able to modify the drawing but not the controls.



Developing Microsoft Visio Solutions 2001
Developing Microsoft Visio Solutions (Pro-Documentation)
ISBN: 0735613532
EAN: 2147483647
Year: 2004
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net