Hi
I am currently working on a piece of code that I am struggling to get working.
I have a picture box that I want to move across the screen. At the moment I want it to stop when it gets to a certain point and you have to click next to move it on to the next point.
I have got the first stage to work but the thing that i can't seem to get to work is getting the picture box to move any further. It just stops there
I was wondering if anyone knew how to get it to work.

Public Class Form1
    Dim nextcommand As Integer = 7
    Dim rewindcommand As Integer = 7
    Dim x As Integer = 144
    Dim y As Integer = 44

    Private Sub NextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextButton.Click
        nextcommand = nextcommand - 1
        Dim position As New System.Drawing.Point(x, y)

        If nextcommand = 6 Then
            Fetch.BackColor = Color.LightYellow
            PictureBox1.Location = position
            Timer1.Interval = 100
            Timer1.Start()
        ElseIf nextcommand = 5 Then
            Fetch.BackColor = Color.DarkSlateGray
            Decode.BackColor = Color.LightYellow
          '  Timer1.Interval = 100
          '  Timer1.Start()
        ElseIf nextcommand = 4 Then
            Decode.BackColor = Color.DarkSlateGray
            Execute.BackColor = Color.LightYellow



Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Static count As Integer = 1
        
        If PictureBox1.Location.X < 20 & PictureBox2.Location.X < 20 Then  'if we haven't reached the stopping point
            PictureBox1.Left += 5              '  Move the Picturebox 100 units to the right.
        Else                                   'otherwise
            Timer1.Enabled = False
            '  PictureBox1.Hide() '  Disable the timer for this example
        End If
        If count = 5 Then
            Timer1.Enabled = False
        End If
        count += 1
    End Sub

I know I have to set the position of the picturebox and I think I have to read the location of it from the form into some integers. I was wondering if anyone knew how to do this and if I am right?

See if this helps.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        'Static count As Integer = 1
        If PictureBox1.Location.X < 20 AndAlso PictureBox2.Location.X < 20 Then  'if we haven't reached the stopping point
            PictureBox1.Left += 5              '  Move the Picturebox 100 units to the right.
        Else                                   'otherwise
            Timer1.Enabled = False
            '  PictureBox1.Hide() '  Disable the timer for this example
        End If
        'If count = 5 Then
        '    Timer1.Enabled = False
        '    count = 1 '// reset count since it is Static and will carry values over for next time.
        'End If
        'count += 1
    End Sub

Only thing I saw wrong was that you were using & instead of AndAlso . AndAlso:D, not resetting your Static Integer.

plzz .. i urgently need to answer this problem..

  • how could i retrieve or extract or get the current location of a certain picturebox during runtime while its moving... and assign its current location to other picturebox.. plz i need help.. in vb.net 2010 ... thank you

Edited 3 Years Ago by Mansibugan

This article has been dead for over six months. Start a new discussion instead.