Visual Basic Reference
X1, Y1, X2, Y2 Properties Example
This example displays an animated line that walks down the form when you click the form. To try this example, paste the code into the Declarations section of a form that contains a Timer control and a Line control, and then press F5 and click the form.
Private Sub Form_Load ()
Timer1.Interval = 100 ' Set Timer interval.
' Position the line near the upper-left corner.
' Set Line1's properties.
With Line1
.X1 = 100
.Y1 = 100
.X2 = 500
.Y2 = 300
End With
Timer1.Enabled = False
End Sub
Private Sub Form_Click ()
Timer1.Enabled = True ' Start the timer.
End Sub
Private Sub Timer1_Timer ()
Static Odd ' Declare variable.
If Odd Then
Line1.X2 = Line1.X2 + 250
Line1.Y2 = Line1.Y2 + 600
Else
Line1.X1 = Line1.X1 + 250
Line1.Y1 = Line1.Y1 + 600
End If
Odd = Not Odd ' Toggle the value.
' If the line is off the form, start over.
If Line1.Y1 > ScaleHeight Then
Timer1.Enabled = False ' Wait for another click.
With Line1
.X1 = 100
.Y1 = 100
.X2 = 500
.Y2 = 300
End With
Odd = False
End If
End Sub