Article ID: 112043
Article Last Modified on 10/29/2003
APPLIES TO
- Microsoft Visual Basic 3.0 Professional Edition
- Microsoft Visual Basic 3.0 Professional Edition
This article was previously published under Q112043
SUMMARY
This article shows by example how to use the SizeMode property of the OLE Control for Visual Basic version 3.0 to obtain a proportional display in a limited screen space.
MORE INFORMATION
The SizeMode property of the OLE Control determines how the OLE control is sized or how its image is displayed when it contains an object.
Here are the valid settings for the SizeMode property:
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.
Step-by-Step Example
The goal of this example is to obtain a proportional display that is restricted to a limited screen space, that of the size of the form the OLE control is on.
The example uses AutoSize and Stretch settings to find a proportional best fit. The height and width of the container form supply the maximum height and width of the image. The Autosize property supplies best-fit information.
Then the Autosize property is set to Stretch mode for display.
- Start Visual Basic or from the File menu, choose New Project (ALT, F, N) if Visual Basic is already running. Form1 is created by default.
- Add an MSOLE2 control to the form. When the Insert Object dialog box asks what type of object to insert, select the Create From File option and a Microsoft Word .DOC file.
- Set the SizeMode property of the OLE control to 1 (Stretch).
Add the following code to the Form_Load event:
Sub Form_Load() OLE1.Top = 0 OLE1.Left = 0 End Sub
Add the following code to the Resize event of the OLE control:
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
- Run the program.
When you double-click the OLE control and make changes to your document, you should see the control itself change size to fit proportionally on your form.
Additional query words: 3.00 OLE Automation OA OLE2
Keywords: KB112043