Jump to content

VB 6.0: Tutorial, How to make a GIF in your application

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
18 replies to this topic

#1
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Introduction/Problem
Well this is a common problem, VB does NOT support GIF's in the Applet, many of you ( I suppose ) make an array of pictureboxes and make still images loaded in them and then in a timer you make the still images to change and well its confusing even to say it, and much more confusing to make! it will take like 8 to 10 lines to just make an animation of 2 frames only! so imagine to make a long GIF! I found this 'secret' and all its going to take is 10 lines! and instead you can have a GIF with unlimited frames and make it with just 10 lines!!

Solution

Start a new Project and select "Standard EXE" as follows:-

Posted Image

Save your project somewhere
how?
see below:-

Posted Image

Add a Picturebox ( Picture1 ) and a web browser control.
HOW?
See this image below

Posted Image
a dialog box will be displayed scroll down till you find "Microsoft Internet Controls" tick it and press OK here is an image to explain better:-

Posted Image
and instead of WebBrowser1 rename it to Animation
and make a GIF image in the same directory where you saved the project and rename it to image.gif

Ok so now make the following code:-

Private Sub Form_Load()
Dim loc As String
Dim Source As String
loc = App.Path & "\image.gif"
Picture1.Visible = False
Picture1.AutoSize = True
Picture1.Picture = LoadPicture(loc)
Animation.Width = Picture1.Width
Animation.Height = Picture1.Height
Source = "about:" & "<html>" & "<body leftMargin=0 topMargin=0 marginheight=0 marginwidth=0 scroll=no>" & "<img src=""" & loc & """></img></body></html>"
Animation.Navigate Source
End Sub

Code Explanation

Dim loc As String
Dim Source As String
Here we are declaring 2 variables loc will be the location of the gif and Source will be some HTML code, dont worry if you dont know HTML! you dont need to because I did it for you

loc = App.Path & "\image.gif"
Here we are asigning the varible loc to the image path, App.path is the location of the project/app and "\image.gif" is the name of the image

Picture1.Visible = False
Picture1.AutoSize = True
Picture1.Picture = LoadPicture(loc)
Well here the code talks on its own
Here we are hiding the picturebox and making it to AutoSize (will take the size of the picture you load (image.gif)) and in the last step we are loading the picture

Animation.Width = Picture1.Width
Animation.Height = Picture1.Height

Here we are making the Webbrowser to take the height and width of the picture1, therefore the size of the GIF!

Source = "about:" & "<html>" & "<body leftMargin=0 topMargin=0 marginheight=0 marginwidth=0 scroll=no>" & "<img src=""" & loc & """></img></body></html>"
This is the HTML code that you will need to display the picture!

Animation.Navigate Source
here we are telling the Webbrowser to execute the Source code!

How does this work?
Simple Just place the browser control where you want to make the picture to appear

Complete Source Code:-
Well I included the FULL source code its an attachment, its the complete project just compile and have fun

IMPORTANT NOTE
With this way if you are going to distribute your application you NEED to distribute the picture TOO!!

Ending:-

If you have any questions/problems/feedback pls post here and I will sureley Help you!
So I'm waiting for your feedback
Ow and if you want me to make you some tutorials request what you want and I will see what I can do! I will be happy making some tuts here!

Tcm9669

Attached Files



#2
AfTriX

AfTriX

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 586 posts
Nice work buddy

#3
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts

AfTriX said:

Nice work buddy

Thanks :) Just a trick of the trade!

#4
AfTriX

AfTriX

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 586 posts
You are welcome!

Each thanks that is welcomed and recorded is a nest egg by the side of which more will be laid..... Juz

#5
oasisjoel

oasisjoel

    Newbie

  • Members
  • Pip
  • 2 posts
I used your... And theres a bug everytime you try to load the form with GIF multiple time's there some kind of ERROR

#6
oasisjoel

oasisjoel

    Newbie

  • Members
  • Pip
  • 2 posts
BTW your program has a bug RUN-Time Error -1

#7
juriani_rahul

juriani_rahul

    Newbie

  • Members
  • Pip
  • 1 posts
awesum

#8
simon8088

simon8088

    Newbie

  • Members
  • Pip
  • 1 posts
great tutorial!

#9
MasterPerkins

MasterPerkins

    Newbie

  • Members
  • Pip
  • 1 posts
most def will try this out!

#10
witcherofhell

witcherofhell

    Newbie

  • Members
  • Pip
  • 1 posts
great work man keep it up

#11
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Welcome.
oasisjoel: Are you following the tutorial correctly?

#12
JustSimple

JustSimple

    Newbie

  • Members
  • Pip
  • 7 posts
Nice...

Btw, how to disable right-click in the image?


Thanks... :)