Making Shapes Flexible with Control Handles

One way to control shape behavior while providing your users with greater flexibility is to add control handles to a shape. Control handles appear as small yellow diamonds that users can select and move. A shape responds to changes in the control handle's position according to your formulas. The real strength of control handles is that they let you design a shape to take advantage of user input.

For ideas about using control handles, look at the shapes that come with Microsoft® Visio®. Each shape with a control handle includes tool tip information describing the handle's behavior. The following figure shows different uses for control handles in a shape.

Visio masters with control handles

Visio masters with control handles

  1. Users can drag out dimension lines and adjust line heights.
  1. Users can drag out lines of any length to connect the token ring.
  1. Users can orient the chair in relation to another shape.

In this section…

Adding a Controls Section to a Shape

Defining a Control Handle

Setting a Control Handle's Anchor Point

Setting a Control Handle's Behavior

Adding a Controls Section to a Shape

To add a control handle to a shape, you add a Controls section in its ShapeSheet® spreadsheet, and then modify formulas in the appropriate row of the Controls section. The Controls section defines control handle attributes. Each row in a shape's Controls section corresponds to a control handle, and cells in each row determine aspects of the control handle's behavior. For example, the Can Glue cell determines whether a control handle can be glued to other shapes, and you can use the Tip cell to define a descriptive tool tip that appears when a user pauses the pointer over a control handle. After adding the Controls section, you can write formulas in other ShapeSheet cells that refer to a row in the Controls section to define that handle's behavior.

For details about adding a control handle to a text block, see Controlling the Text Block's Position in Chapter 9, Designing Text Behavior.

TOP

Defining a Control Handle

You use the cells in the Controls section to define the location and behavior of a shape's control handles. For example, you might create a word balloon with a mouthpiece that can be repositioned by adding a control handle that controls a vertex of the shape, as the following figure shows. In this example, you want the word balloon to be a two-dimensional (2-D) shape with an alignment box around the rectangle part only so that the position of the control handle doesn't affect the rest of the shape.

Control handle defined for a vertex of a word balloon

Control handle (A) defined for a vertex of a word balloon. Use a control handle to reposition the mouthpiece.

The location of the control handle is defined by the formula in a Geometry cell.

The location of the control handle is defined by the formula in a cell in the Geometry section. To attach the sixth vertex to a control handle (A), enter the control handle reference in this Geometry cell (B).

To draw the word balloon shape

  1. Use the Line tool to draw the rectangle with the mouthpiece inverted, as illustrated below.
  1. Protect the shape from width/height recalculation by setting the LockCalcWH cell in the Protection section of the shape's sheet to TRUE (or 1). This maintains the rectangle's original alignment box when the mouthpiece is moved using the control handle.

In the following procedure, you'll add a Controls section and formulas to associate the control handle with the mouthpiece vertex.

To add a control handle to the word balloon shape

  1. Open the ShapeSheet window for the word balloon shape. On the Insert menu, click Section, select the Controls check box, and then click OK.
  • When you add the Controls section to a shape, a control handle with the coordinates
  • Width*0
  • ,
  • Height*0
  • is created in the section and added to the shape on the drawing page. You can move the control handle with the mouse, but it won't do anything until you associate the shape's geometry with it in some way—typically you would associate it with the vertex you want the handle to control.
  1. Put references to the control handle's position (the Controls.Xn and Controls.Yn cells) in the cells in the Geometry section that correspond to the vertex you want to control with the handle.
  • In general, you enter a formula that refers to the
  • x
  • -coordinate of a control handle in an X cell of the Geometry section and a formula that refers to its
  • y
  • -coordinate in a Y cell. If you drew the word balloon segments in the order shown in the preceding figure, the mouthpiece vertex is controlled by Geometry row 6. For this example, you would enter the following formulas:
  • Geometry1.X6    = Controls.X1
  • Geometry1.Y6    = Controls.Y1
  • The mouthpiece seems to vanish, because you have temporarily assigned its vertex to the local coordinates 0,0 (the result of the control handle's default formulas
  • Width*0,Height*0
  • ).
  1. Drag the control handle in the drawing window to make the mouthpiece reappear.
  • Or, position the mouthpiece by changing the control handle's default formulas (for example, to
  • Width*0.75,Height*-0.5
  • ).
  1. The X Dynamics and Y Dynamics cells describe the control handle's anchor point, which is connected to the control handle with a dynamically drawn black line when live dynamics has been turned off. For details, see Setting a Control Handle's Anchor Point later in this section. For this example, leave the default values unchanged.
  1. In the X Behavior and Y Behavior cells, enter a constant from zero (0) to 9 to determine how the control handle repositions as the shape resizes. For this example, enter the following constants:
  • X Behavior    = 4
  • Y Behavior    = 2
  • For details, see
  • Setting a Control Handle's Behavior
  • later in this section. For constants that you can use in the cells of the Controls section, see the cell topics associated with the Controls section in the Microsoft Visio Developer Reference (on the
  • Help
  • menu, click
  • Developer Reference
  • ).
  1. The Can Glue cell of a control handle determines whether a control handle can be glued to other shapes. For this example, leave the default value unchanged.
  1. In the Tip cell, enter a string for the control handle tool tip.

TOP

Setting a Control Handle's Anchor Point

Each control handle you define has an anchor point on the shape in relation to which it is drawn. The anchor point is defined by the formulas in the control point's X Dynamics and Y Dynamics cells.

Live dynamics functionality updates shape geometry as a user moves a control handle. When live dynamics is disabled, a black "rubber-band" line stretches between the anchor point and the control handle as the user drags the handle. This rubber-band line serves as a visual aid to help users determine where the control handle is being moved to and what will happen to the shape as a result. The location of the anchor point does not affect how the shape appears on the page, but only how the rubber-band line appears as the user moves the control handle.

When live dynamics is enabled, the anchor point has no visible effect and the control handle moves with the mouse pointer. To disable live dynamics for a drawing (it is enabled by default), click Options on the Tools menu, click the General tab, and clear the Enable live dynamics check box.

You can set the anchor point at any position in relation to the shape using the X Dynamics and Y Dynamics cells. By default, the anchor point appears at the position of the control handle. However, you can position the anchor point in a fixed location relative to the shape. For example, to set a control handle's anchor point at the bottom of a shape, enter the following formula:

To set the anchor point at the center of a shape, enter the following formulas:

  • X Dynamics    = Width/2
  • Y Dynamics    = Height/2

Note The live dynamics feature is not available in versions of Visio earlier than Visio 2000.

TOP

Setting a Control Handle's Behavior

When a user stretches a shape that has a control handle, you can specify how the handle behaves when the shape is stretched—whether the control handle moves in proportion to the shape or stays in the same place relative to the shape. If you want to fix the position of a control handle, you can hide it so a user cannot drag it.

To change display properties for control handles, you can set the following values in the shape's sheet:

  • Set the NoCtrlHandles cell in the Miscellaneous section to true to prevent control handles from appearing when a user selects a shape. This has the same effect as using the X or Y Behavior cell to make a handle hidden, but overrides X and Y Behavior settings that make the handles visible. For details on settings for X Behavior and Y Behavior cells, see the following table.
  • Set the UpdateAlignBox cell in the Miscellaneous section to true to cause a shape's alignment box to recalculate whenever a user moves a vertex. When a vertex is associated with a control handle, this causes the alignment box to be updated when the control point is moved. If the LockCalcWH cell (Protection section) is set to true (or 1), UpdateAlignBox has no effect until LockCalcWH is set to false.

You can also use the values of the X Behavior and Y Behavior cells in the Controls section to define a control handle's position and behavior, as the following table describes. The X Behavior and Y Behavior cells operate independently of each other.

Settings for X Behavior and Y Behavior cells

Visible

Hidden

Control handle behavior when shape is stretched

0

5

Moves in proportion with the shape when the shape is stretched.

1

6

Moves in proportion with the shape, but cannot be moved horizontally (X Behavior) or vertically (Y Behavior).

2

7

Offsets a constant distance from the shape's left side (X Behavior) or bottom (Y Behavior).

3

8

Offsets a constant distance from the center of the shape.

4

9

Offsets a constant distance from the shape's right side (X Behavior) or top (Y Behavior).

For example, the following figure shows a word balloon with a control handle whose X Behavior value is 4 and Y Behavior value is 2.

The X and Y Behavior cells control the position of the control handle relative to the shape's outline.

The X and Y Behavior cells control the position of the control handle relative to the shape's outline.

  1. The control handle is offset a constant distance from the shape's right and bottom.
  1. If the shape is stretched using the handles on the left or top, the control handle stays anchored.
  1. If the shape is stretched using the bottom or right handles, the control handle moves to retain the offset.