GIF Animation As Icon On VB Form

dudefromthebronx

New member
Joined
Jan 31, 2012
Messages
4
Programming Experience
Beginner
See that icon in the upper left of the form, right next to 'Form1'?


ScreenHunter_01 Jan. 31 15.48.jpg

I'd like to put a GIF animation in place of that icon in VB Express 2010. Anybody know how?
 
It's not possible. In Windows terms, an icon is a specific format and it's not compatible with GIF. That icon in the title bar must be an Icon object, so you can't use a GIF. You would have to have multiple Icon objects and use a Timer to set the Icon property of the form at intervals.
 
Hi there, I wanted to do this a while back, put a ComboBox in the title bar, and the only way I could get it to work is set the FormBorderStyle to None and draw the border onto the form. You can place a PictureBox over the icon location. Would need to make your own ControlBox buttons though.
 
While it is true that you cannot have an animation there, you could in principle change that icon programatically. That is to say, if you split your "icon" gif into one icon file for each frame, you could set the icon on the program to one of those files at regular time intervals. However, it's worth asking yourself whether the resource cost and potential annoyance of this feature outweighs the benefits. Unless there is some particular reason for wanting this I'd suggest sticking to a static icon anyway.
 
    Private animated As New Bitmap("animated.gif")
    Private frameindex As Integer
    Private framecount As Integer = animated.GetFrameCount(Imaging.FrameDimension.Time)

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        frameindex = If(frameindex = framecount - 1, 0, frameindex + 1)
        animated.SelectActiveFrame(Imaging.FrameDimension.Time, frameindex)
        Me.Icon.Dispose()
        Me.Icon = Icon.FromHandle(animated.GetHicon)
    End Sub
 
Or subclass a form object and as stated draw an image on top of the regular icon...

VB.NET:
Public Class FormWithElaborateIcon
    Inherits Form
    Protected Overrides Sub OnPaint(e As PaintEventArgs)
        MyBase.OnPaint(e)
        e.Graphics.DrawImage(ImageObject, x, y, Width, Height)
    End Sub
End Class

Combine that with the previous tidbit form John and you can animate it.
 
Last edited:
Or subclass a form object and as stated draw an image on top of the regular icon...

VB.NET:
Public Class FormWithElaborateIcon
    Inherits Form
    Protected Overrides Sub OnPaint(e As PaintEventArgs)
        MyBase.OnPaint(e)
        e.Graphics.DrawImage(ImageObject, x, y, Width, Height)
    End Sub
End Class

Combine that with the previous tidbit form John and you can animate it.

That's not going to work. The Paint event will only help you draw on the client area of the form. The title bar is part of the non-client area. To draw on it directly is a relatively complex affair, which is those who want to use GDI+ for this sort of thing have to hide the real border and draw their own.
 
Back
Top