The OLE control's SizeMode property controls how the OLE control displays an OLE object. Table 18.3 lists the possible settings for the SizeMode property.
Table 18.3 - SizeMode Property Settings
SizeMode Constant | Value | Use |
---|---|---|
vbOLESizeClip (default) | 0 | Clips the object to fit in the control |
vbOLESizeStretch | 1 | Stretches or shrinks the object's height and width to match the control without retaining the object's original proportions |
vbOLESizeAutoSize | 2 | Resizes the control to match the object's height and width |
vbOLESizeZoom | 3 | Stretches or shrinks the object's height and width to match the control while retaining the object's original proportions |
If the OLE control does not match the size of the OLE object that it contains, Visual Basic triggers a Resize event for the object. The Resize event has the following form for the OLE control:
Private Sub OLE1_Resize(HeightNew As Single, WidthNew As Single) ' ... your code here. End Sub
The HeightNew and WidthNew arguments indicate a recommended size for the object. This size is that of the OLE object in its original form. You can use these arguments with the SizeMode property to control the scaling of an OLE object. To learn more about this technique, see the section "Scaling the Object to Fit the Control," later in this chapter.
The Resize event occurs when the displayed size of an OLE object changes, as in the situations described in Table 18.4.
Table 18.4 - Situations That Result in a Resize Event
A Resize Event Occurs When | If the Current Size Mode Setting Is |
---|---|
A new object is inserted in the control. | Any setting |
The size of an object changes because it was updated. | Any setting but vbOLESizeClip |
The OLE control's Height and Width properties are used to change the object's size. | Any setting but vbOLESizeClip |
The SizeMode property changes to a new setting. | vbOLESizeClip |
The SizeMode property changes to vbOLESizeAutosize. | vbOLESizeStretch or vbOLESizeZoom |
The Resize event does not occur when SizeMode changes from any setting to vbOLESizeClip or vbOLESizeAutoSize to any setting. In the latter situation, the control size matches the object size, so no visual change occurs, either.