home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Samples / SCROLVB / SCROLVB.ZIP / SCROLL-1.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-02-01  |  9.0 KB  |  241 lines

  1. VERSION 2.00
  2. Begin Form frmMain 
  3.    Caption         =   "Scroll-1 Demo"
  4.    Height          =   3180
  5.    Icon            =   SCROLL-1.FRX:0000
  6.    Left            =   1650
  7.    LinkTopic       =   "Form1"
  8.    ScaleHeight     =   185
  9.    ScaleMode       =   3  'Pixel
  10.    ScaleWidth      =   249
  11.    Top             =   1500
  12.    Width           =   3855
  13.    Begin PictureBox picCorner 
  14.       BackColor       =   &H00C0C0C0&
  15.       Height          =   255
  16.       Left            =   120
  17.       ScaleHeight     =   225
  18.       ScaleWidth      =   225
  19.       TabIndex        =   3
  20.       Top             =   120
  21.       Width           =   255
  22.    End
  23.    Begin CommandButton cmdStart 
  24.       Caption         =   "&Start"
  25.       Height          =   375
  26.       Left            =   2040
  27.       TabIndex        =   0
  28.       Top             =   120
  29.       Width           =   1575
  30.    End
  31.    Begin VScrollBar vsb1 
  32.       Height          =   1455
  33.       LargeChange     =   50
  34.       Left            =   120
  35.       SmallChange     =   10
  36.       TabIndex        =   2
  37.       Top             =   480
  38.       Width           =   255
  39.    End
  40.    Begin HScrollBar hsb1 
  41.       Height          =   255
  42.       LargeChange     =   50
  43.       Left            =   480
  44.       SmallChange     =   10
  45.       TabIndex        =   1
  46.       Top             =   120
  47.       Width           =   1455
  48.    End
  49.    Begin PictureBox picBig 
  50.       BackColor       =   &H00FFFF00&
  51.       BorderStyle     =   0  'None
  52.       Height          =   2055
  53.       Left            =   480
  54.       ScaleHeight     =   137
  55.       ScaleMode       =   3  'Pixel
  56.       ScaleWidth      =   209
  57.       TabIndex        =   4
  58.       Top             =   600
  59.       Width           =   3135
  60.       Begin CommandButton cmdExit 
  61.          Caption         =   "E&xit"
  62.          Height          =   375
  63.          Index           =   0
  64.          Left            =   120
  65.          TabIndex        =   9
  66.          Top             =   1560
  67.          Width           =   2895
  68.       End
  69.       Begin Label lblDownRight 
  70.          Alignment       =   2  'Center
  71.          BorderStyle     =   1  'Fixed Single
  72.          Caption         =   "to the four corners!"
  73.          Height          =   255
  74.          Left            =   120
  75.          TabIndex        =   8
  76.          Top             =   1200
  77.          Width           =   2895
  78.       End
  79.       Begin Label lblDownLeft 
  80.          Alignment       =   2  'Center
  81.          BorderStyle     =   1  'Fixed Single
  82.          Caption         =   "and these labels will be moved"
  83.          Height          =   255
  84.          Left            =   120
  85.          TabIndex        =   7
  86.          Top             =   840
  87.          Width           =   2895
  88.       End
  89.       Begin Label lblUpRight 
  90.          Alignment       =   2  'Center
  91.          BorderStyle     =   1  'Fixed Single
  92.          Caption         =   "the picture box will be enlarged,"
  93.          Height          =   255
  94.          Left            =   120
  95.          TabIndex        =   6
  96.          Top             =   480
  97.          Width           =   2895
  98.       End
  99.       Begin Label lblUpLeft 
  100.          Alignment       =   2  'Center
  101.          BorderStyle     =   1  'Fixed Single
  102.          Caption         =   "When you click ""Start"","
  103.          Height          =   255
  104.          Left            =   120
  105.          TabIndex        =   5
  106.          Top             =   120
  107.          Width           =   2895
  108.       End
  109.    End
  110. ' SCROLL-1.FRM - Declarations.
  111.     DefInt A-Z
  112. ' End Of Declarations.
  113. Sub cmdExit_Click (Index As Integer)
  114. ' Completely self explanatory!
  115.     End
  116. End Sub
  117. Sub cmdStart_Click ()
  118. ' Hide the Start button right away.
  119.     cmdStart.Visible = False
  120. ' Move and enlarge the scrolling picture box.
  121. ' The "600, 400" can be changed to any reasonable size,
  122. ' up to a maximum of 16,383 by 16,383 pixels.
  123. ' If AutoRedraw=True then larger sizes use a _LOT_ more memory.
  124.     picBig.Move 0, 0, 600, 400
  125. ' Move the four labels out to the corners of picBig. These are not critical,
  126. ' and they aren't necessary for scrolling the picBig box.
  127.     lblUpLeft.Move 0, 0
  128.     lblUpRight.Move (picBig.Width - lblUpRight.Width), 0
  129.     lblDownLeft.Move 0, (picBig.Height - lblDownLeft.Height)
  130.     temp1 = picBig.Width - lblUpRight.Width
  131.     temp2 = picBig.Height - lblDownLeft.Height
  132.     lblDownRight.Move temp1, temp2
  133. ' Now duplicate the "Exit" command button a few times, just to have some
  134. ' other sample controls on the form. These are not critical, and can be
  135. ' removed and replaced with any other kind of control.
  136.     For temp = 1 To 7
  137.     Load cmdExit(temp)
  138.     Next temp
  139. ' Organize the little Exit buttons - just to have something else to scroll.
  140. ' The following code is NOT critical, and isn't necessary for scrolling the
  141. ' picBig box. You would normally put more MEANINGFUL controls onto the box,
  142. ' for example: Text boxes, command buttons, picture boxes, labels, option
  143. ' buttons, just about anything!
  144.     For x = 0 To 7
  145.     cmdExit(x).Move 75 + (x * 50), 50 + (x * 40), 100, 20
  146.     cmdExit(x).Visible = True
  147.     Next x
  148. ' Move the scroll bars to their correct locations.
  149.     Call FixScrollBars
  150. End Sub
  151. Sub FixScrollBars ()
  152. ' Assume you won't need to display anything.
  153.     vertFLAG = False
  154.     horizFLAG = False
  155.     cornerFLAG = False
  156. ' Figure out how much WIDTH of the picture box is hidden now,
  157. ' and if any width is hidden, you need a horizontal scroll bar.
  158.     HiddenX = (picBig.Width) - (frmMain.ScaleWidth)
  159.     If HiddenX > 0 Then horizFLAG = True
  160. ' Figure out how much HEIGHT of the picture box is hidden now,
  161. ' and if any height is hidden, you need a vertical scroll bar.
  162.     HiddenY = (picBig.Height) - (frmMain.ScaleHeight)
  163.     If HiddenY > 0 Then vertFLAG = True
  164. ' If horizontal scroll bar is ON, then slightly less height is available,
  165. ' so re-check the height.
  166.     If horizFLAG = True Then
  167.     HiddenY = (picBig.Height - 1) - (frmMain.ScaleHeight - hsb1.Height)
  168.     If HiddenY > 0 Then vertFLAG = True
  169.     End If
  170. ' If vertical scroll bar is ON, then slightly less width is available,
  171. ' so re-check the width.
  172.     If vertFLAG = True Then
  173.     HiddenX = (picBig.Width - 1) - (frmMain.ScaleWidth - vsb1.Width)
  174.     If HiddenX > 0 Then horizFLAG = True
  175.     End If
  176. ' If both scroll bars are ON, then turn on the corner box.
  177.     If (horizFLAG = True) And (vertFLAG = True) Then cornerFLAG = True
  178. ' At this point, you know if hsb1/vsb1/picCorner will be ON or OFF,
  179. ' so if anything will be OFF, make it invisible now. This section doesn't
  180. ' make anything visible, because if something is invisible, it's better
  181. ' to leave it that way until AFTER it is moved.
  182.     If horizFLAG = False Then hsb1.Visible = False
  183.     If vertFLAG = False Then vsb1.Visible = False
  184.     If cornerFLAG = False Then picCorner.Visible = False
  185. ' Move the vertical scroll bar over to the right side of the form,
  186. ' and make sure it's visible.
  187.     If vertFLAG = True Then
  188.     ' Top is always 0.
  189.         vsb1.Top = 0
  190.     ' Find the new height - but watch out for negative numbers.
  191.         tempVH = frmMain.ScaleHeight - hsb1.Height + 2
  192.         If horizFLAG = False Then tempVH = frmMain.ScaleHeight + 1
  193.         If tempVH > 0 Then vsb1.Height = tempVH
  194.     ' Find the new left - but watch out for negative numbers.
  195.         tempVL = frmMain.ScaleWidth - vsb1.Width + 1
  196.         If tempVL > 0 Then vsb1.Left = tempVL
  197.     ' Show it.
  198.         vsb1.Visible = True
  199.     End If
  200. ' Move the horizontal scroll bar down to the bottom of the form,
  201. ' and make sure it's visible.
  202.     If horizFLAG = True Then
  203.     ' Left is always 0.
  204.         hsb1.Left = 0
  205.     ' Find the new width - but watch out for negative numbers.
  206.         tempHW = frmMain.ScaleWidth - vsb1.Width + 2
  207.         If vertFLAG = False Then tempHW = frmMain.ScaleWidth + 1
  208.         If tempHW > 0 Then hsb1.Width = tempHW
  209.     ' Find the new top - but watch out for negative numbers.
  210.         tempHT = frmMain.ScaleHeight - hsb1.Height + 1
  211.         If tempHT > 0 Then hsb1.Top = tempHT
  212.     ' Show it.
  213.         hsb1.Visible = True
  214.     End If
  215. ' Move the little grey corner box to the lower right corner of the form.
  216. ' It's always the same width as vsb1, and the same height as hsb1,
  217. ' so even if those sizes are different, the corner will be perfect.
  218.     If cornerFLAG = True Then
  219.     picCorner.Move tempVL, tempHT, vsb1.Width, hsb1.Height
  220.     picCorner.Visible = True
  221.     End If
  222. ' Fix scroll bar values - so you can scroll to the hidden areas of picBig.
  223. ' These two lines are CRITICAL, and they're the key to the entire program.
  224.     vsb1.Max = HiddenY
  225.     hsb1.Max = HiddenX
  226. End Sub
  227. Sub Form_Resize ()
  228. ' Every time the form is resized, you need to move the scroll bars around.
  229.     Call FixScrollBars
  230. End Sub
  231. Sub hsb1_Change ()
  232. ' Move the picture box to the left (into invisible negative numbers).
  233. ' Note the MINUS SIGN before "hsb1.value".
  234.     picBig.Left = -hsb1.Value
  235. End Sub
  236. Sub vsb1_Change ()
  237. ' Move the picture box up (into invisible negative numbers).
  238. ' Note the MINUS SIGN before "vsb1.value".
  239.     picBig.Top = -vsb1.Value
  240. End Sub
  241.