Results 1 to 3 of 3

Thread: Draw line and timer?

  1. #1

    Thread Starter
    Fanatic Member Avatarp's Avatar
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    826

    Draw line and timer?

    I am drawing a line from point A to B. I want it to take about 1 second to complete. I also want to have the line draw at run time and appear to draw over that 1 second from A to B. I am doing it with a for loop and running a variable up to a very high count. This isnt an effiecent way of doing it. Here is my code:

    Code:
    Private Sub cmdClientMenu_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If cmdFind.Visible = True Then
            Exit Sub
        End If
        lineMC.Visible = True
        lineMC.X1 = 2520
        lineMC.Y1 = 2880
        MyXPos = lineMC.X1
        MyYPos = lineMC.Y1
        For i = 0 To 110000
            If i = 10000 Or i = 20000 Or i = 30000 Or i = 40000 Or i = 50000 Or i = 60000 _
                Or i = 70000 Or i = 80000 Or i = 90000 Or i = 100000 Or i = 110000 Then
                frmSalon.lineMC.X2 = MyXPos + 120
                frmSalon.lineMC.Y2 = MyYPos - 120
                frmSalon.Refresh
                MyXPos = frmSalon.lineMC.X2
                MyYPos = frmSalon.lineMC.Y2
            End If
        Next
        frmSalon.cmdFind.Visible = True
    End Sub
    Any help would be great.

  2. #2
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857
    VB Code:
    1. Option Explicit
    2.  
    3. Dim i As Integer
    4. Const LINE_LENGTH As Integer = 6000
    5.  
    6. Private Sub Form_Load()
    7.     With Line1
    8.         .Visible = False
    9.         .X1 = 200
    10.         .X2 = 200
    11.         .Y1 = 1000
    12.         .Y2 = 1000
    13.     End With
    14. End Sub
    15. Private Sub Command1_Click()
    16.     With Timer1
    17.         .Interval = 25
    18.         .Enabled = True
    19.     End With
    20.     With Line1
    21.         .Visible = True
    22.         .X1 = 200
    23.         .X2 = 200
    24.         .Y1 = 1000
    25.         .Y2 = 1000
    26.     End With
    27.     i = 0
    28. End Sub
    29. Private Sub Timer1_Timer()
    30.     i = i + Timer1.Interval
    31.     If i = 1000 Then
    32.         Timer1.Enabled = False
    33.     Else
    34.         IncrementLine
    35.     End If
    36. End Sub
    37. Private Sub IncrementLine()
    38.     Dim sngPercent As Single
    39.     sngPercent = i / 1000
    40.     Line1.X2 = (LINE_LENGTH * sngPercent) + Line1.X1
    41. End Sub

    This just needs a commandbutton, a timer and a line. You may have to play with the timer interval a bit to get the effect you want - drawing the line takes time so it isn't very accurate, but I think it will get you started.
    "Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!

    Resistance is futile, you will be compiled . . . Please!

  3. #3

    Thread Starter
    Fanatic Member Avatarp's Avatar
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    826

    Thanks Armbruster

    You code looks like it will go easier on memory than my loop. I'll fool around with it.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width