Understanding Attachments

Introduction

Attachments control the spatial relationships between the graphical user interface elements on a window when the window is resized. For example, with the appropriate attachments defined, you can make a control expand when the user enlarges the window, enabling the user to see more data. With a few simple attachments you can greatly increase the utility of an application.
This appendix is a brief introduction to attachments. It guides you through the process of defining attachments so that when a user enlarges the Display_data frame, the Table Viewer on that frame will also grow larger so that more data is visible.
Default Width of Display_data Frame
Default Width of Display_data Frame
Expanded Display_data Frame with Attachments Defined
Expanded Display_data Frame using Attachments

Control Representation in Attach Mode

When you define attachments, the controls on a frame are represented by wire outlines. Compare the regular, build time TestFrame to the frame while defining attachments.
TestFrame at Build Time (left) and in Attach Mode (right)
TestFrame at Build Time (left) and in Attach Mode (right)

Attachment Points

You define attachments between a control and the edge of the frame, or between the edge or center of two controls.
An attachment to the edge of a control causes that edge to move when the other end of the attachment (the anchor) is moved. An attachment to the center of a control causes the entire control to move when the anchor for that attachment is moved. Attachments are represented as arrows in the graphical user interface.
In the following display the top Push Button control is attached from its right edge to the right edge of the frame. The lower Push Button control is attached from its center to the right edge of the frame.
TestFrame with Edge and Center Attachments
TestFrame with Edge and Center Attachments
As you can see in the following display, when the frame is enlarged horizontally at run time, the top Push Button (Button1) expands to the right (the edge attachment), and the bottom Push Button (Button2) moves with the right edge of the frame (the center attachment).
TestFrame at Run Time Before and After Expansion
TestFrame at Run-Time Before and After Expansion

Attachment Direction and Type

When you start defining attachments, the Define Attachment dialog box appears so that you can select the direction and type of attachment.
The Define Attachment Dialog Box
The Define Attachment Dialog Box
The direction of the attachment governs which control changes when the anchor of the attachment is moved. The control that the attachment arrow points to responds to the moving of the anchor. Remember that an attachment can be anchored to the edge or center of another control, or to the edge of the frame. The left arrow direction is the default attachment direction, and it is the only direction that is used in the example later in this appendix.
Attachment Directions
Icon
Direction
Description
Bidirectional
Bidirectional
Both controls respond to resizing or moving either control. In effect, both ends of the attachment are anchors.
Single direction right
Single Direction
(Right)
The control that the arrow points to responds to a move of the anchor.
single direction left
Single Direction
(Left)
The control that the arrow points to responds to a move of the anchor.
The type of attachment defines the distance between the anchor and the arrow either in terms of pixels between the points (an absolute attachment type), or as a percentage of space between the points (a relative attachment type). The absolute attachment type is the default attachment type, and it is the only type of attachment that is used in the example later in this appendix.
Attachment Types
Icon
Type
Description
absolute
Absolute
Maintains a fixed number of pixels between attachment points
Relative
Relative
Maintains a percentage of space between attachment points
Delete
Delete
Deletes attachments (see Deleting and Altering Attachments)

Moving Controls That Are Attached

Before you define any attachments, you should adjust the size of the frame and arrange the controls as you want them to be displayed at run time. Once defined, attachments are honored at build time, and if you move an anchor (on a control or a frame), any attached controls are moved or resized according to the attachments.
However, you can select and move multiple controls at build time while not in attach mode without having attachments honored.
In attach mode you can both move and resize individual controls without attachments being honored. The alignment tools are not available in attach mode.

Deleting and Altering Attachments

You cannot alter the direction or type of an attachment after it has been created. To change an attachment you must delete it and then create a new attachment.
To delete an attachment, follow these steps after you are in attach mode:
  1. Select the delete type (the attachment direction is unimportant).
    Select the Deletion attachment type
  2. Click inside the control where the attachment is pointing to the control. Do not click on the attachment line itself—doing so will not delete the attachment.

For More Information about Attachments

There are many other ways to control screen geometry using attachments. For more information, see the Guide to SAS/AF Applications Development, available at support.sas.com/documentation/onlinedoc/af/.