This is a late answer but hopefully someone will benefit from it, below is what I have done to animate the image in the TabPage, I used it to show an animated loading icon, this assumes that you have extracted the frames of the GIF and included them in the resources.
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;
namespace GuiLib
{
public class AnimatedTabControl : TabControl
{
static int ITEM_WIDTH = 250;
static int ITEM_HEIGHT = 25;
static int TIMER_INTERVAL = 80;
static int ICON_X = 3;
static int ICON_Y = 3;
static int ICON_WIDTH = 15;
static int ICON_HIGHT = 15;
static int TEXT_X = 50;
static int TEXT_Y = 6;
static int TEXT_WIDTH = 200;
static int TEXT_HIGHT = 15;
int animationIndex;
static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
Bitmap[] animationImages = {new Bitmap(GuiLib.Properties.Resources._0), new Bitmap(GuiLib.Properties.Resources._1),new Bitmap(GuiLib.Properties.Resources._2),
new Bitmap(GuiLib.Properties.Resources._3),new Bitmap(GuiLib.Properties.Resources._4),new Bitmap(GuiLib.Properties.Resources._5),
new Bitmap(GuiLib.Properties.Resources._6),new Bitmap(GuiLib.Properties.Resources._7)};
Bitmap animatedimage;
public AnimatedTabControl()
: base()
{
this.DrawMode = TabDrawMode.OwnerDrawFixed;
this.SizeMode = TabSizeMode.Fixed;
this.ItemSize = new Size(ITEM_WIDTH, ITEM_HEIGHT);
myTimer.Tick += new EventHandler(TimerEventProcessor);
myTimer.Interval = TIMER_INTERVAL;
animationIndex = 0;
}
private void TimerEventProcessor(Object myObject, EventArgs myEventArgs)
{
animationIndex++;
if (animationIndex >= animationImages.Length)
animationIndex = 0;
animatedimage = animationImages[animationIndex];
AnimateLoadingTabsOrStopIfNonIsLoading();
}
private void AnimateLoadingTabsOrStopIfNonIsLoading()
{
bool stopRunning = true;
for (int i = 0; i < this.TabPages.Count; i++)
{
if (this.TabPages[i] is LoadingTabPage)
{
LoadingTabPage ltp = (LoadingTabPage)this.TabPages[i];
if (ltp.Loading)
{
stopRunning = false;
Rectangle r = GetTabRect(i);
this.Invalidate(new Rectangle(r.X + ICON_X, r.Y + ICON_Y, ICON_WIDTH, ICON_HIGHT));
}
}
}
if (stopRunning)
myTimer.Stop();
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
Rectangle r = e.Bounds;
r = GetTabRect(e.Index);
DrawAnimationImageIfLoading(e, r);
DrawTabTitle(e, r);
}
private void DrawTabTitle(DrawItemEventArgs e, Rectangle r)
{
string title = this.TabPages[e.Index].Text;
StringFormat titleFormat = new StringFormat();
titleFormat.Trimming = StringTrimming.EllipsisCharacter;
e.Graphics.DrawString(title, this.Font, Brushes.Black, new RectangleF(r.X + TEXT_X, r.Y + TEXT_Y, TEXT_WIDTH, TEXT_HIGHT), titleFormat);
}
private void DrawAnimationImageIfLoading(DrawItemEventArgs e, Rectangle r)
{
if (this.TabPages[e.Index] is LoadingTabPage)
{
if (((LoadingTabPage)this.TabPages[e.Index]).Loading)
{
if (animatedimage != null)
e.Graphics.DrawImage(animatedimage, new RectangleF(r.X + ICON_X, r.Y + ICON_Y, ICON_WIDTH, ICON_HIGHT));
if (!myTimer.Enabled)
myTimer.Start();
}
}
}
}
}
And the LoadingTabPage as this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace GuiLib
{
/// <summary>
/// A Class to facilitate tab page with animated loading icon.
/// </summary>
public class LoadingTabPage : TabPage
{
public LoadingTabPage(string s)
: base(s)
{
loading = false;
}
public LoadingTabPage()
: base()
{
loading = false;
}
private bool loading;
public bool Loading
{
get { return loading; }
set
{
loading = value;
if (this.Parent != null)
{
this.Parent.Invalidate();
}
}
}
}
}
The usage will be easy:
myLoadingTabPage.Loading = true;
Android actually can decode and display animated GIFs, using android.graphics.Movie class.
This is not too much documented, but is in SDK Reference. Moreover, it is used in Samples in ApiDemos in BitmapDecode example with some animated flag.
Best Answer
You can use TBitmapListAnimation with a single image which has each frame of the animation inside a long strip. eg, if your animation has 4 frames and is 32px by 32px then you need to create an image 128px wide by 32px high and add each frame side by side...
Then add a TImage to the form (you don't have to load a bitmap into this)
Add a TBitmapListAnimation with the TImage as it's parent
Double click AnimationBitmap and load your animation image strip
Drop down PropertyName and pick Bitmap
Set AnimationCount to 4 and AnimationRowCount 1 for this example
Set enabled to true
TBitmapListAnimation has good control over animation frame rates, reversing, looping and interpolation. I couldn't find a way to get a .gif to animate in FireMonkey2 but if you have the means to convert an animated .gif into a 'cartoon strip' then this is a good way to do animations.
PS This is Delphi XE3...so can't say if these components existed in previous version.