Visual Basic Reference

ScaleLeft, ScaleTop Properties Example

This example creates a grid in a PictureBox control and sets coordinates for the upper-left corner to -1, -1 instead of 0, 0. Every 0.25 second, dots are randomly plotted from the upper-left corner to the lower-right corner. To try this example, paste the code into the Declarations section of a form that contains a large PictureBox and a Timer control, and then press F5.

  Private Sub Form_Load ()
   Timer1.Interval = 250   ' Set Timer interval.
   Picture1.ScaleTop = -1   ' Set scale for top of grid.
   Picture1.ScaleLeft = -1   ' Set scale for left of grid.
   Picture1.ScaleWidth = 2   ' Set scale (-1 to 1).
   Picture1.ScaleHeight = 2
   Picture1.Line (-1, 0)-(1, 0)   ' Draw horizontal line.
   Picture1.Line (0, -1)-(0, 1)   ' Draw vertical line.
End Sub

Private Sub Timer1_Timer ()
   Dim I   ' Declare variable.
   ' Plot dots randomly within a range.
   For I = -1 To 1 Step .05
      Picture1.PSet (I * Rnd, I * Rnd)   ' Draw a point.
   Next I
End Sub