Animating Text In Picture Box

  • 14 years ago

    HELP ME!! Please help me, im doing a porject and i dont no how to animate text in a picturebox. Im doin a keypress game and the user is to press the letters that move down the picturebox to score points. i can generate the letters but i just dont n how to animate the text so that it drops down also i need it to start at random points across the top of the picture box x coordinates any help will be greatly apreciated

  • 14 years ago

    Hi,

    I think you can achieve this with timer controls. Just to get an idea try this.

    Add a picture box (picture1), label (label1) on picture box, 2 timer controls (timer1 and timer2) to a form. Set the interval of timer1 to 1 and timer2 to 1000. Paste the following code and run.

    Private Sub FormLoad()
    Label1.Left = Picture1.Left
    Label1.Top = Picture1.Top
    End Sub

    Private Sub Timer1
    Timer()
    If Label1.Left + Label1.Width = Picture1.Left + Picture1.Width Then
        Label1.Left = Picture1.Left
    End If
    'change 5 to a value you want depening how fast you want to scroll horizontally.
    Label1.Left = Label1.Left + 5
    End Sub

    Private Sub Timer2_Timer()
    'change 1000 to a value you want depending on how random you want to move vertically and also 'depending on the height of the picture box.
    Label1.Top = Picture1.Top + Rnd * 1000
    End Sub

    I hope this helps.

    cheers
    Prakash.




























  • 14 years ago

    thanx this does help but how do you mean. label in a pictur box. Tongue Tied [:S] thanx for the help btw

  • 14 years ago

    sorry am an idiot n av wurked it out cheers doestn matter now lol

  • 14 years ago

    By the sounds of it, you need to have characters fall from the top of the screen, and you're using a picturebox to display all this. If you were using C++, I could easily help, BUT I do know that you can print text onto a picturebox.

    As an example, this will print "A" to the picture box at the given co-ordinates. PB is the picturebox.

    Dim textX as Integer
    Dim textY as Integer
    Dim strText as String

    strText = "A" ' change to whatever
    textX = 50 ' ie. left, 50 pixels in
    textY = 50 ' ie. top, 50 pixels in

    PB.CurrentX = textX
    PB.CurrentY = textY
    PB.Print strText









    I'm not 100% sure, but you may have to clear the picturebox and redraw after each change otherwise the text may stay (which looks cool but is not what you want). Do so with

    PB.Picture = LoadPicture( "" ) ' clears the picturebox

    I hope this helps and isn't too late!

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Measuring programming progress by lines of code is like measuring aircraft building progress by weight.” - Bill Gates