I don't know how to implement this. I tried several times. but the button was only visible if the picturebox is already in the width of the frm(Me.WIdth)

Public Class Form1

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Static XInteger As Integer = PictureBox1.Left
        Static YInteger As Integer = PictureBox1.Top
        Static WidthInteger As Integer = PictureBox1.Width
        Static HeightInteger As Integer = PictureBox1.Height
        XInteger -= 10
        If XInteger <= -PictureBox1.Width Then
            XInteger = Me.Width
        End If
        PictureBox1.SetBounds(XInteger, YInteger, WidthInteger, HeightInteger)
        'button should be invisible if the picture is in the ending point of the button

    End Sub
End Class
6 Years
Discussion Span
Last Post by Reverend Jim

I'm going to take a guess at your problem. I'm thinking you have a form with a button and a picturebox. You want to repeatedly move the picturebox left in small steps with a wraparound to the right side of the form. You also want to make the button invisible if any part of it overlaps the picture. Going on that assumption it makes sense to create a separate function that can be user generically to determine if one control overlaps another. That function looks like:

    Private Function Within(ctrl1 As Control, ctrl2 As Control) As Boolean

        'returns True if and part of ctrl1 lies within ctrl2

        'get the coordinates of the top left and bottom right corners of both controls

        Dim c1x1 As Integer = ctrl1.Location.X
        Dim c1y1 As Integer = ctrl1.Location.Y
        Dim c1x2 As Integer = c1x1 + ctrl1.Size.Width - 1
        Dim c1y2 As Integer = c1y1 + ctrl1.Size.Height - 1

        Dim c2x1 As Integer = ctrl2.Location.X
        Dim c2y1 As Integer = ctrl2.Location.Y
        Dim c2x2 As Integer = c2x1 + ctrl2.Size.Width - 1
        Dim c2y2 As Integer = c2y1 + ctrl2.Size.Height - 1

        'return true if the top left corner of ctrl1 is within ctrl2 or
        'the bottom right corner of ctrl1 is within ctrl2

        If c1x1 >= c2x1 And c1x1 <= c2x2 And c1y1 >= c2y1 And c1y1 <= c2y2 Then Return True
        If c1x2 >= c2x1 And c1x2 <= c2x2 And c1y2 >= c2y1 And c1y2 <= c2y2 Then Return True

        Return False

    End Function

So try using this function and see if you can get it working.

Edited by Reverend Jim

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.