Using Locks to Limit Shape Behavior

Most actions in the drawing page change a shape's formulas and so can affect the specialized behavior and custom formulas you have designed for the shape. You can set constraints on shape behavior, called locks, that prevent particular actions on the drawing page.

For example, consider a grand piano. Pianos come in different sizes, but they are built only one way—the shorter strings are always to the right as you face the keyboard. To protect this characteristic, you would lock a grand piano shape against horizontal flipping. A user could still rotate the piano shape—as you could if you were pushing a real piano around the room—but not flip it.

One of the simplest ways to protect your shapes is to set the lock cells in the Protection section of the ShapeSheet® window. Some cells in the Protection section correspond to options in the Protection dialog box (on the Format menu, click Protection); others can be set only in a ShapeSheet window. For details about Protection cells, see the Microsoft Visio Developer Reference (on the Help menu, click Developer Reference).

Setting locks prevents accidental changes to a shape. For example, if your shapes represent items with standard dimensions, such as building materials, you can lock their resizing handles, because users shouldn't be able to stretch the shapes in all directions. Setting some locks causes a padlock symbol to appear in place of some or all selection handles on the shape, indicating that the feature cannot be changed.

Setting protection locks gives the user visual feedback as padlocks which indicate the shape can't be resized

Setting protection locks gives the user visual feedback. Padlocks (A) indicate that you cannot resize the shape.

To lock a feature, set the appropriate cell in the Protection section to a non-zero number. To unlock a feature, enter 0 in the cell.

Setting locks doesn't affect the menu commands that are enabled and doesn't protect other formulas from change. For example, if you lock the width and height of a shape that is in a group, and then scale the group, the width and height of the shape can change. Locking prevents the user only from scaling the shape with the mouse. For more information about controlling what users can do with groups, see Chapter 6, Grouping and Merging Shapes.

Note You can also use the GUARD function in your custom formulas to prevent them from being overwritten by user or Visio actions. The GUARD function and protection locks protect your shapes in complementary ways. The guard function prevents formulas from changing, but it allows user actions. By contrast, setting locks in the Protection section prevents user actions without protecting cell formulas.

For example, if you set a shape's Width formula to = GUARD( 5 pica ), users can drag the shape's side selection handles to stretch the shape, but the shape snaps back to its original width as soon as Visio reevaluates its Width formula. However, if you set the LockWidth cell to TRUE (1), users cannot drag the side selection handles in the first place.

For details about guard, see Designing Visio Formulas in Chapter 4, Visio Formulas. Also see the ShapeSheet Reference in the Microsoft Visio Developer Reference (on the Help menu, click Developer Reference).