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 / zoom.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-08-12  |  3.6 KB  |  120 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   3228
  5.    ClientLeft      =   1332
  6.    ClientTop       =   2076
  7.    ClientWidth     =   4572
  8.    Height          =   3780
  9.    Left            =   1284
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3228
  12.    ScaleWidth      =   4572
  13.    Top             =   1572
  14.    Width           =   4668
  15.    Begin VB.VScrollBar VScroll1 
  16.       Height          =   3252
  17.       Left            =   4320
  18.       TabIndex        =   0
  19.       Top             =   0
  20.       Width           =   252
  21.    End
  22.    Begin VB.OLE OLE1 
  23.       Height          =   3252
  24.       Left            =   0
  25.       SizeMode        =   3  'Zoom
  26.       TabIndex        =   1
  27.       Top             =   0
  28.       Width           =   4332
  29.    End
  30.    Begin VB.Menu mnuFile 
  31.       Caption         =   "&File"
  32.       NegotiatePosition=   1  'Left
  33.       Begin VB.Menu mnuNew 
  34.          Caption         =   "&New Object"
  35.       End
  36.       Begin VB.Menu mnuClose 
  37.          Caption         =   "&Close Object"
  38.       End
  39.       Begin VB.Menu mnuSep1 
  40.          Caption         =   "-"
  41.       End
  42.       Begin VB.Menu mnuExit 
  43.          Caption         =   "E&xit"
  44.       End
  45.    End
  46. Attribute VB_Name = "Form1"
  47. Attribute VB_Creatable = False
  48. Attribute VB_Exposed = False
  49. Option Explicit
  50. Dim msHeightRatio As Single, msWidthRatio As Single
  51. Dim msIdealHeight As Single, msIdealWidth As Single
  52. Dim msActualHeight As Single, msActualWidth As Single
  53. Dim mResized As Boolean
  54. Private Sub Form_Load()
  55.     ' Keep control the same size.
  56.     OLE1.SizeMode = vbOLESizeZoom
  57.     ' Display the Insert Object dialog on startup.
  58.     OLE1.InsertObjDlg
  59. End Sub
  60. Private Sub Form_Resize()
  61.     ' Move scroll bar
  62.     AdjustScrollBars Me
  63.     ' Resize OLE object.
  64.     OLE1.Height = Me.Height
  65.     ' Allow resize action
  66.     mResized = False
  67.     OLE1.Width = Me.Width - VScroll1.Width
  68. End Sub
  69. Private Sub mnuClose_Click()
  70.     OLE1.Close
  71. End Sub
  72. Private Sub mnuExit_Click()
  73.     End
  74. End Sub
  75. Private Sub mnuNew_Click()
  76.     mResized = False
  77.     OLE1.InsertObjDlg
  78. End Sub
  79. Private Sub OLE1_Resize(HeightNew As Single, WidthNew As Single)
  80.     ' Get the actual height and width of the object
  81.     ' from the application.
  82.     If Not mResized Then
  83.         ' Get the control size.
  84.         msActualHeight = OLE1.Height
  85.         msActualWidth = OLE1.Width
  86.         ' Temporarily switch SizeMode to get
  87.         ' the actual size.
  88.         OLE1.SizeMode = vbOLESizeAutoSize
  89.         ' Get the actual height and width of the object.
  90.         msIdealHeight = OLE1.Height
  91.         msIdealWidth = OLE1.Width
  92.         ' Reset size mode and height/width
  93.         OLE1.SizeMode = vbOLESizeZoom
  94.         OLE1.Height = msActualHeight
  95.         OLE1.Width = msActualWidth
  96.         ' Choose which ratio is greater.
  97.         msHeightRatio = OLE1.Height / msIdealHeight
  98.         msWidthRatio = OLE1.Width / msIdealWidth
  99.         ' Use the greater ratio for the scroll bar zoom.
  100.         If msHeightRatio >= msHeightRatio Then
  101.             ' Set the maxium value (400%)
  102.             VScroll1.MAX = msWidthRatio * 4
  103.        Else
  104.             ' Set the maxium value (400%)
  105.             VScroll1.MAX = msWidthRatio * 4
  106.        End If
  107.         ' Set the initial scrollbar position.
  108.         VScroll1.MIN = 1
  109.         VScroll1.VALUE = 1
  110.        ' Set module-level variable.
  111.        mResized = True
  112.     End If
  113. End Sub
  114. ' Zoom OLE control.
  115. Private Sub VScroll1_Change()
  116.     ' Scale Height and Width.
  117.     OLE1.Height = msActualHeight * VScroll1.VALUE
  118.     OLE1.Width = msActualWidth * VScroll1.VALUE
  119. End Sub
  120.