Article ID: 112043
Article Last Modified on 10/29/2003
0 (Default) Clip -- The object is displayed in actual size. If the object is larger than the OLE control, its image is clipped by the control's borders, showing the upper-left portion of the image. 1 Stretch -- The object's image is sized to fill the OLE control. The height of the image is stretched (or shrunk) to fit the OLE control. The same thing happens to the width. As a result, you may get a distorted image. Height and width are independent, not proportional. 2 Autosize -- The OLE control is resized to display the entire object. The object is displayed in actual size. By using the resize event of the OLE control, you can adjust the HeightNew and WidthNew parameters to maintain size limits of the OLE control. However, the display behaves as if you had used the clip setting.
Sub Form_Load()
OLE1.Top = 0
OLE1.Left = 0
End Sub
Sub OLE1_Resize (heightNew As Single, WidthNew As Single)
Dim wRatio As Single, hRatio As Single, cRatio As Single
Dim MaxHeight As Single, MaxWidth As Single
If OLE1.SizeMode = 2 Then
MaxHeight = Me.Height
MaxWidth = Me.Width
'Calculate hRatio
If heightNew > MaxHeight Then
hRatio = 1 - (heightNew - MaxHeight) / heightNew
Else
hRatio = 1 + (MaxHeight - heightNew) / heightNew
End If
'Calculate wRatio
If WidthNew > MaxWidth Then
wRatio = 1 - (WidthNew - MaxWidth) / WidthNew
Else
wRatio = 1 + (MaxWidth - WidthNew) / WidthNew
End If
'Pick best ratio for cRatio
If hRatio < wRatio Then
cRatio = hRatio
Else
cRatio = wRatio
End If
'Apply changes
OLE1.Height = CInt(cRatio * heightNew)
OLE1.Width = CInt(cRatio * WidthNew)
OLE1.SizeMode = 1
ElseIf OLE1.SizeMode = 1 Then
'Use AutoSize to recalculate ratio.
OLE1.SizeMode = 2
End If
End Sub
Additional query words: 3.00 OLE Automation OA OLE2
Keywords: KB112043