Link to home
Start Free TrialLog in
Avatar of rebert_herry
rebert_herry

asked on

animation in vb

I have vb 4.0 and I would like tp put a .gif file for
background on the vb application. If that possible ?
You can assume I have back.gif file. You can design a empty
or just very simple appplication and the background will be
back.gif.

I would like a complete code.

Thank you
ASKER CERTIFIED SOLUTION
Avatar of ameba
ameba
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rebert_herry
rebert_herry

ASKER

ok , it is a vb application, it isn't a Wallpaper on my desktop.
Just a animation file on the vb application form.
I have tried to set  Form1.Picture , but when I ran the apllication, it gave me a run time error,
said that my back.gif is not allowed.
Did you set picture property? It is allowed, I think from VB4/32 (it is not in the file type list, you must use All Files to select it).
When do you get error - when setting property or when running application? And you cannot use annimated .GIF - I tried simple GIF, it works.
I think it gave me an error, when I set the property.
you say you tried simple gif and it worked, why not you gave me the code
I think it will help me a lot. thank you
Try another GIF or JPG.
I didn't use any code. I just set property "Picture" of a form.
But, you can use code:

Private Sub Form_Load()
    Form1.Picture = LoadPicture("E:\Win95\MSAPPS\GRPHFLT\ms.gif")
End Sub

Maybe it works here in my VB4, because I have also VB5 on the same PC.
ok ! It is working, I can see the gif file as background. But I have told you it is animation file. But I just can't see the background changed. Why ?
Because it is not supported in VB. To have animation, you will have to use timer and change background picture yourself.
But animated GIF and JPG files will show only first plane.

To use GIF and JPG you will have to use a control. E.g. you can try WEB browser control. To try this, press add form and then select "Browser" from existing templates. Set its MDIChild property to False. You can then use:

Private Sub mnuViewBrowser_Click()
    Dim frmB As New frmBrowser
    frmB.StartingAddress = "E:\WIN95\Desktop\cookbook.gif"
    frmB.Show
End Sub

But, WEB browser control is not good background. You can place some controls (e.g. Command buttons) on top of it, but for some controls (labels, shapes) you will have to add Picturebox as container. Labels alone will always go behind WEB browser control.
You will also have to require IE4 instalation for your programs to work.

So, I suggest modifying picture in Timer event and not using animated GIFs.
OK. If I want to use timer event . How ? like
I have 3 files named f1.gif, f2.gif and f3.gif. These files will be  used as background.
So, first gif will be f1.gif, then after 1 second, will be change to f2.gif and so on, repeatly.
How ?
Can you gave me a complete code ?
Thank a lot ?
Add Picture Box to your form. Set its visible property to False and Index to 0.
Now copy Picture1 and paste 2 times.
You have Picture1(0),Picture1(1) and Picture1(2). Set Picture property for your picture boxes to be "f1.gif", "f2.gif", "f3.gif"
Add timer control, set Interval=1000
Add this code:
Private Sub Timer1_Timer()
    Static flop As Integer
    flop = flop + 1
    If flop = 3 Then flop = 0
    Picture = Picture1(flop).Picture
End Sub

' ClipControls of your form must be set to True