Solved

GIF's in Visual Basic

Posted on 2002-06-09
19
250 Views
Last Modified: 2013-11-25
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
0
Comment
Question by:m_durnell
  • 7
  • 5
  • 5
  • +1
19 Comments
 
LVL 5

Expert Comment

by:Leithauser
ID: 7065469
 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.
0
 
LVL 1

Author Comment

by:m_durnell
ID: 7065490
I would consider anything, thanks for your help, but how do I go about using this control - Where is it?
Cheers!
 
0
 
LVL 5

Expert Comment

by:Leithauser
ID: 7065507
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.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7065829
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7066344
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

0
 
LVL 5

Expert Comment

by:Leithauser
ID: 7067042
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.
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7069159
but did'nt you want to make it "Move"????
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7069907
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"?
0
 
LVL 1

Author Comment

by:m_durnell
ID: 7078009
Hi,

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

Mark
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7078411
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
0
 
LVL 5

Expert Comment

by:Leithauser
ID: 7078643
m_durnell:

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

Author Comment

by:m_durnell
ID: 7079686
Hi,

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

0
 
LVL 5

Expert Comment

by:Leithauser
ID: 7079941
  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.
0
 
LVL 1

Author Comment

by:m_durnell
ID: 7080872
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
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7081094
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.
0
 
LVL 5

Accepted Solution

by:
Leithauser earned 100 total points
ID: 7081687
<<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.>>

   I do not understand. If you include the
Call WebBrowser1.Navigate(MyFile.gif)
in the Form_Load module of the form, the graphic should be in place before the form becomes visible. You might even include a DoEvents right after the call. Is this not happening properly?
0
 
LVL 1

Author Comment

by:m_durnell
ID: 7084068
It worked perfect.  Thanks for that - It made me think a little.

Regards

Mark
0
 
LVL 5

Expert Comment

by:Leithauser
ID: 7084330
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.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7085017
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
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

774 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question