Can you help me with my code snipplet

#Region "Object Movement"
Private Sub FullScreenOBJ_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'I have a timer, I am trying to move the Image to a random corner of the screen
'The Image is contained in a picturebox
'The Timer is set to 1000ms (or 1 Second)
'I want it to move the object to the next random corer everytime
'The timer is done
'how do I make this happen.
'There should also be a way to determine when 30 seconds have passed so that
'the application closes this form


Do
Dim tty As New System.Random
Dim strtty As String = ""
strtty = tty.Next(1, 4)

If strtty = "1" Then
PictureBox1.ImageLocation = "12, 12"
End If
If strtty = "2" Then
PictureBox1.ImageLocation = "877, 12"
End If
If strtty = "3" Then
PictureBox1.ImageLocation = "12, 622"
End If
If strtty = "4" Then
PictureBox1.ImageLocation = "12, 877"

End If
Loop
End Sub
#End Region

Comments

  • Update, I forgot to mention it is contained within a borderless form

  • I posted some code in reply to this the other day, and it appears as though it didn't enter the system. So here goes again.

    First put this function in your project:

    [code]
    '''
    ''' Generates a Random Number
    '''
    ''' The minimum Value to be returned
    ''' The Maximum Value to be returned
    '''
    '''
    Friend Function RandomNumber(ByVal min As Int32, ByVal max As Int32) As Int32
    Dim intMax As Int32 = max + 1
    Dim random As New Random()
    Return random.Next(min, intmax)
    End Function

    [/code]

    Then Add this code to timer event

    [code]

    Dim RandNumber As Int32 = RandomNumber(1, 4)
    'The Code assumes your picture control is named PictureBox1
    With PictureBox1
    Select Case RandNumber
    Case 1
    'Aligns control to top left hand corner of form
    .Left = 0
    .Top = 0


    Case 2
    'Aligns control to top right hand corner of form
    .Left = Me.Width - .Width
    .Top = 0
    Case 3
    'Aligns control to bottom left hand corner of form
    .Left = 0
    .Top = Me.Height - .Height
    Case 4
    'Aligns control to bottom right hand corner of form
    .Left = Me.Width - .Width
    .Top = Me.Height = .Height

    End Select
    End With

    'Close form after 30 Seconds
    Static SecondCount As Int32 = 0
    SecondCount = SecondCount + 1

    If (SecondCount >= 30) Then
    Me.Close
    End If

    'Note this may not close the on an exact 30 seconds, as I believe the timer control doesn't fire exactly on time, but it should be fairly close.
    [/code]

    The RandomNumber function has been tested as it has been copied directly from my own project. The rest of the code has been untested, so some adjustments may be needed.




  • Wow! Thank you for the coding.
    You will be glad to know that I will be giving you full credit
    for you work in the release of iTrain.

    Please check it out at:
    http://www.sourceforge.net/projects/itrain

    I am always looking for help so if you would like to join (or dedicate some time to developing the application that would rule)

    No I just have to figure out why the image will not move to the lower right hand corner of the screen.

    Thank you though
  • I am sorry as I said the timer event code was untested, and there appears to be a problem with my code.

    The code I wrote for case 4 which was

    [code]
    Case 4
    'Aligns control to bottom right hand corner of form
    .Left = Me.Width - .Width
    .Top = Me.Height = .Height
    [/code]

    Should have been

    [code]
    Case 4
    'Aligns control to bottom right hand corner of form
    .Left = Me.Width - .Width
    .Top = Me.Height - .Height
    [/code]

    I had put in an = instead of a -
  • *Now not no (on the previous reply of mine)
    -------------------------------------------

    Anyway, thank you my friend for the quick edit, I do not know why I skipped it when scan reading.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories