home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Programmer'…arterly (Limited Edition)
/
Visual_Basic_Programmers_Journal_VB-CD_Quarterly_Limited_Edition_1995.iso
/
code
/
ch13code
/
listings
/
13list02.txt
< prev
next >
Wrap
Text File
|
1995-08-03
|
3KB
|
75 lines
' Listing 13LIST02.TXT
' Automatically adjust the control to fit the object.
OLE1.SizeMode = vbOLESizeAutosize
' Display the Insert Object dialog
' to get an object to display.
' Show FileOpen dialog to get a file to open.
CommonDialog1.FileName = "*.*"
CommonDialog1.ShowOpen
' Check if file exists before creating link
' (see Function below).
If FileExists(CommonDialog1.FileName) Then
Attempt to create an embedded object.
OLE1.CreateLink CommonDialog1.FileName
End If
' OLE1.InsertObjDlg
End Sub
' Checks if a file exists (uses full path and file name).
Function FileExists(strFileName) As Boolean
' Turn on error checking.
On Error Resume Next
' FileLen causes error if file doesn't exist.
FileLen (strFileName)
If Err Then
FileExists = False
Err = 0
Else
FileExists = True
End If
' Turn off error checking.
On Error GoTo 0
End Function
Private Sub HScroll1_Change()
OLE1.Left = 0 - HScroll1.Value
End Sub
Private Sub VScroll1_Change()
OLE1.Top = 0 - VScroll1.Value
End Sub
Private Sub OLE1_Resize(HeightNew As Single,
WidthNew As Single)
If HeightNew > Form1.Height Then
VScroll1.Visible = True
VScroll1.Max = HeightNew
VScroll1.LargeChange = _
HeightNew / (HeightNew / OLE1.Height)
VScroll1.SmallChange = VScroll1.LargeChange / 10
Else
VScroll1.Visible = False
End If
If WidthNew > Form1.Width Then
HScroll1.Visible = True
HScroll1.Max = WidthNew
HScroll1.LargeChange = WidthNew / _
(WidthNew / OLE1.Width)
HScroll1.SmallChange = HScroll1.LargeChange / 10
Else
HScroll1.Visible = False
End If
End Sub
Private Sub Form_Resize()
' Skip first Resize on Load.
Static bFlag As Boolean
If bFlag Then
' If form resizes, trigger OLE control
' resize behavior.
OLE1_Resize OLE1.Height, OLE1.Width
Else
bFlag = True
End If
' Call support procedure to adjust the placement
' and size of scroll bars on the form.
AdjustScrollBars Me
End Sub