Animating images inside a picture box

02-01-2002, 01:16 AM
Hi there. :)

I'm really just starting out so forgive the newbieness.

Basically, what I'm trying to do is move an image that's loaded from a loadpicture command inside a picture box in a specific way.

The image is a 22x220 bitmap that makes up a stacked series of frames.

All that needs to happen is for the image to be moved upwards 22 pixels at a time in order to get some rudimentary animation happening and cycle when it reaches the bottom.

There may be another way, but the basic guidelines I've got to work to are that...

(1) The picture is loaded by the user, so the script has to work around the pciturebox/placeholder of the image or something.

(2) I used a picture box because it masks off any overlapping bits of the image, only displaying a 22x22 pixel area at a time.
There might be another way to do this, I don't know. :P

If anyone knows of an easy way to do this I'd be very much in your debt, and I'd be happy to return the favour in some way be it through links or possibly a custom graphic or two. :)

Cheers in advance for any help ventured.



02-01-2002, 02:27 AM
OK, I'd suggest using BitBlt because this is fast, simple and allows for easy positioning.

Basically, you pass an hDC, and XY, and a source for the picture, and its copied. You'd need two pictureboxes, one to load the picture into, and another to display it. When your form loads, use your loadpicture command on it, then use BitBlt to transfer it to the visible box. Using a timer, BitBlt it again, only y-22....
Declare Function BitBlt Lib "gdi32" _
(ByVal hDestDC As Integer, ByVal x As Integer, _
ByVal y As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal _
hSrcDC As Integer, ByVal xSrc As Integer, _
ByVal ySrc As Integer, ByVal dwRop As _
Long) As Integer

Dim yPos As Integer

Private Sub Form_Load()
' set the form
Me.ScaleMode = vbPixels
picMain.AutoRedraw = True
' load the picture
picHidden.Picture = LoadPicture(your_path)
' copy it
yPos = 0
BitBlt picMain.hDc, 0,yPos,picMain.ScaleWidth,picMain.ScaleHeight,picHidden.hDc,0,0,vbSrcC opy
End Sub

Private Sub Timer1_Timer()
yPos = yPos - 22
BitBlt picMain.hDc, 0,yPos,picMain.ScaleWidth,picMain.ScaleHeight,picHidden.hDc,0,0,vbSrcC opy
End Sub

02-01-2002, 12:12 PM
Cool stuff man. Cheers for that. :D

I'll give it a try tonight and see if I can get it working. :)

Thanks again for the help. :D

I'll report back with something to show soon hopefully. :)

Being a complete newbie I'm still getting my head around what exactly all the terminolgy means, but I'll get there in the end, on step at a time. :)



Whoo. I just got told off for having too many smileys in my post, I overstreched the smiley limit.

02-05-2002, 05:09 PM
I know I'm touching on an old subject but wouldn't this be a case where FLASH would do the trick better than VB code?

Just a though, I know how you guys hate flash from that one post about it but I can't resist to bring it up.

02-05-2002, 05:12 PM
I think I'll refrence you to that thread so you can why "Flash" would not be better, rather than reposting my arguments here.

"I know I'm touching on an old subject but wouldn't this be a case where FLASH would do the trick better than VB code?"

Nope. Not in my opinion.

02-05-2002, 05:16 PM
Please, this is a VB forum, not a Flash forum. This is where we talk about serious games.

Rest deleted by ArnoutV

02-07-2002, 12:01 PM

Yeah, it'd be exceptionally easy in flash but the point would be missed. ;) And I'm not anti flash by any means ( See for proof ;))

I'm still messing about with various bit trying to get this to go.

It should be really simple, but at the moment, since I'm a vb newbie, the task comparable to writing a novel in German, without actually being able to speak german and with only a couple of buisness prase books and a dodgy 1950's dictionary.

Is there a way to arrange the image INSIDE the picture box, [i]without[i/] manipulating the box itself?

On the surfice the task seemed easy but I've still had no joy. :(

Basically, all the program needs to do is take a bmp ( 22 x 220 ) , basically a 'stack' of ten 22 x 22 in one image, and basically scroll the image in increments of 22 and loop.

It's basically the way IE animates it's little "E" logo in the corner when a page is loading, and I need to be able to do the same thing, with the same image, or one that is loaded by the user.

Is there an easy way to to this, some REALLY simple way?

Redbull I apreciate the script, but for all my trying, I can't get anything to work from it. The Bitblt thing doesn't seem to like my VB, or at least, my VB throws up errors when I use it.



02-07-2002, 12:17 PM
John, Could you attach your project so we can see what might be going wrong with your BitBlt code?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum