Link to home
Start Free TrialLog in
Avatar of m_durnell
m_durnellFlag for United Kingdom of Great Britain and Northern Ireland

asked on

GIF's in Visual Basic

Is it possible to display a gif in VB using the picture box or image control, and if so how do I do it?  I have been able to display the gif in the application but it shows up as a 'static' image.  Is there any way that I can make it "Move"?

Thanks

Mark
Avatar of Leithauser
Leithauser

 Would you consider using a WebBrowser control instead of a picture or image control? Have the WebBrowser control load your gif file using
Call WebBrowser1.Navigate(MyFile.gif)
  You would have to distribute the gif file with the program, but the WebBrowser control does respond to click and such.
Avatar of m_durnell

ASKER

I would consider anything, thanks for your help, but how do I go about using this control - Where is it?
Cheers!
 
The following directions may vary slightly, depending on which version of VB you are using. These are for VB 4.

Click on Tools/Custom controls.
Scroll down to Microsoft Internet Controls
Click on the box to mark it with an X
Click on the OK button.

This should add a control to your toolbar that looks like Earth. Add this control to yor form and size it like you would any other control.

To display the gif, put the code
Call WebBrowser1.Navigate(MyFile.gif)
somewhere, probably in the Form Load module. Where I have used MyFile.gif above, include the path to your gif. If the gif is in the same folder as the app, MyFile.gif should be sufficient.
Avatar of Richie_Simonetti
I guess what m_durnell wants is to make his image "move". If one puts it in an image control or picture control or a web control, this again would remain static.

Maybe you can put a timer control with your image or a picture control. Try something like this:

Put an couple of image/picture controls on your form along with a Timer control

Set the Timer controls "Interval" property as 1000 (ie 1 sec) and in the Timer1_Timer() event show the gif file in different picture boxes hiding and showing it. That is show Picture1 and hide picture2 and picture 3.
Assuming you have loaded your gifs to picture1, 2 and 3.

This is just a workaround. I dont think the finish would be smooth enough. But obviously you wont have a static gifs. The user will surely feel that it is an animation but surely not a static image.

Hope you can try this.

-priya

It seems to me that my suggestion of using the WebBrowser control to display the image is simpler. I gave it a quick test on my computer and it seems to work fine.
but did'nt you want to make it "Move"????
H i m_durnell, any progress?
Maybe there is a misconception here: when you say "move", yiu are talking about "animation an animated gif" or "moving the image from, ie, point A to point B"?
Hi,

Richie is right I want to use an animated gif.  I dont want to move the image from one point to another.

Mark
If you don't want to use the code from www,mvps.org/vbnet you could use a third party control called anigif.ocx.
http://www.allapi.net/php/redirect/redirect.php?action=download&id=86
http://www.allapi.net/php/redirect/redirect.php?action=download&id=342
m_durnell:

   Did you try out the suggestion I made to put a WebBrowser control on the form? Worked fine for me.
Hi,

I do not know how to add the control that Leithauser suggested I am using version 6.

  In VB 6, Click on the Projects menu at the top. Click on Components. Scroll down to Microsoft Internet controls and click on the box to check it. Click on Apply button and then Ok button. A picture of Earth will appear on your tool bar. Use this just like any other control, like a picture box, to put it on your form and size it.
   The picture cannot be selected during design time, so you must distrubute the gif along with the project and put
Call WebBrowser1.Navigate(MyFile.gif) in the form Load module. The gif should show in the control and be fully animated, just like it looks in a Web page. Experiment with sizing the box to fit the gif. Let me know if you have any other questions.
Leithauser,

I managed to get it to work as you suggested, although I can get it to work by setting up a button (when clicked) I would like it to appear at start up.  Any ideas from you would be appreciated.

Regards

Mark
Of course you could use the approach that you like but just take in mind two things:
1) Wasted resources
2) You need to "hide" scroll bar too.
ASKER CERTIFIED SOLUTION
Avatar of Leithauser
Leithauser

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
It worked perfect.  Thanks for that - It made me think a little.

Regards

Mark
To Richie Simonetti:
   If your comment was in regard to my suggestion of using the WebBrowser control, there is no scroll bar if you size the control precisely to fit the gif. Rememebr, you are talking about knowing exactly what image you plan to put there, so a little experimentation in the design stage can size the control perfectly to fit the gif that will go there.
   As for wasted resources, any way you do it, ther ewill be some wasted resource. In general, the WebBrowser control can be one alternative to displaying images that are meant for Web pages.
Leithauser, nothing against you in my comment.
I used webbrowser control to display animated gif (and Java applets) until i found a less resource usage way.
regarding scrollbar, there is not a great problem. I know a couple of ways to hide it without know the exact size of the image.
Happy codding!
Cheers