home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / wrap-a1a / scroller.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-10-08  |  3.8 KB  |  115 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Scroller"
  4.    ClientHeight    =   1635
  5.    ClientLeft      =   1140
  6.    ClientTop       =   1515
  7.    ClientWidth     =   6690
  8.    Height          =   2040
  9.    Left            =   1080
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   1635
  12.    ScaleWidth      =   6690
  13.    Top             =   1170
  14.    Width           =   6810
  15.    Begin VB.Timer Timer1 
  16.       Left            =   4440
  17.       Top             =   480
  18.    End
  19.    Begin VB.Label Label2 
  20.       Caption         =   "Label2"
  21.       Height          =   255
  22.       Left            =   1680
  23.       TabIndex        =   1
  24.       Top             =   240
  25.       Width           =   1815
  26.    End
  27.    Begin VB.Label Label1 
  28.       Caption         =   "Label1"
  29.       Height          =   255
  30.       Left            =   120
  31.       TabIndex        =   0
  32.       Top             =   240
  33.       Width           =   1455
  34.    End
  35. Attribute VB_Name = "Form1"
  36. Attribute VB_Creatable = False
  37. Attribute VB_Exposed = False
  38. Private Sub Form_Load()
  39. 'give Label1 a caption
  40. Label1.Caption = "Look ma! wrap-around scrolling!"
  41. 'Autosize both labels
  42. Label1.AutoSize = True
  43. Label2.AutoSize = True
  44. 'Uniform the labels
  45. Label2.Top = Label1.Top
  46. Label2.Caption = Label1.Caption
  47. 'Hide label2 offscreen
  48. Label2.Left = Form1.Width + 20
  49. 'Set the timer to a nice smooth time
  50. timer1.Interval = 90
  51. 'Enable the timer
  52. timer1.Enabled = True
  53. 'Store the Form's width in case of resize
  54. FrmSize$ = Form1.Width
  55. End Sub
  56. Private Sub Form_Resize()
  57. '*******************************
  58. 'NOTE: this section is only needed if the form is going to change size
  59. '*******************************
  60. 'We dont want crashes from devide by 0
  61. If FrmSize$ > 0 Then
  62.     'If Label2 is farther from the forms left border
  63.     'than Label1 then
  64.     If Label1.Left < Label2.Left Then
  65.         'make sure Label2 stays offscreen
  66.         Label2.Left = Form1.Width + 20
  67.         'find how far (percent) the label is across the old screen
  68.         Percnt$ = Label1.Left / FrmSize$
  69.         'find out the distance where the label should be
  70.         'based on the percentage and put it there
  71.         Label1.Left = Form1.Width * Percnt$
  72.     End If
  73.     'If Label1 is farther from the forms left border
  74.     'than Label2 then
  75.     If Label2.Left < Label1.Left Then
  76.         'make sure Label2 stays offscreen
  77.         Label1.Left = Form1.Width + 20
  78.         'find how far (percent) the label is across the old screen
  79.         Percnt$ = Label2.Left / FrmSize$
  80.         'find out the distance where the label should be
  81.         'based on the percentage and put it there
  82.         Label2.Left = Form1.Width * Percnt$
  83.     End If
  84. End If
  85. 'Store the form width just in case we have to go through
  86. 'this again
  87. FrmSize$ = Form1.Width
  88. End Sub
  89. Private Sub timer1_Timer()
  90. 'If Label1 is farther from the forms left border
  91. 'than Label2 then
  92. If Label1.Left < Label2.Left Then
  93. 'move the Label1 closer to the left border
  94. Label1.Left = Label1.Left - 25
  95. 'If the Label1 is completely offscreen then send it
  96. 'to the other side of the form to wait for its turn
  97. If Label1.Left + Label1.Width <= 0 Then Label1.Left = Form1.Width + 10
  98. 'If Label1 is partially hidden then start scrolling
  99. 'Label2
  100. If Label1.Left < 0 Then Label2.Left = Form1.Width + Label1.Left
  101. End If
  102. 'If Label2 is farther from the forms left border
  103. 'than Label1 then
  104. If Label2.Left < Label1.Left Then
  105. 'move the Label2 closer to the left border
  106. Label2.Left = Label2.Left - 25
  107. 'If the Label2 is completely offscreen then send it
  108. 'to the other side of the form to wait for its turn
  109. If Label2.Left + Label2.Width <= 0 Then Label2.Left = Form1.Width + 10
  110. 'If Label2 is partially hidden then start scrolling
  111. 'Label1
  112. If Label2.Left < 0 Then Label1.Left = Form1.Width + Label2.Left
  113. End If
  114. End Sub
  115.