Solved

GIF's in Visual Basic

Posted on 2002-06-09
19
247 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
Comment Utility
 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
Comment Utility
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
Comment Utility
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
0
 
LVL 2

Expert Comment

by:priya_pbk
Comment Utility
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
Comment Utility
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
Comment Utility
but did'nt you want to make it "Move"????
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 16

Expert Comment

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

Regards

Mark
0
 
LVL 5

Expert Comment

by:Leithauser
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now