Here in this blog, we will explain an approach on HowTo implement AnimatedCellType. For our demonstration, we will create a custom cell type from ImageCellType which will handle .gif images updation outside of the sheet. This is a two step process:
- Paint cells using PaintCell() method
- Notify updation of the frame for painting using OnFrameChanged() method.
For implementation of the same we will use .Net Framework's ImageAnimator class which animates an image that has time-based frames.
Following code can be used to paint the image frame per second rate using PaintCell() method:
public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
if (currentImage == null)
base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);
else lock (currentImage)
base.PaintCell(g, r, appearance, currentImage, isSelected, isLocked, zoomFactor);
Notify Updation of Frame
Now once the painting of cells is done, we need to notify updation of the frame for painting depending on frame per second rate. This will be done using OnFrameChanged() method as shown in the code below :
void OnFrameChanged(object sender, EventArgs e)
int rv = sheet.FpSpread.GetRowViewportCount();
int cv = sheet.FpSpread.GetColumnViewportCount();
Rectangle spreadRect = sheet.FpSpread.Bounds;
for (int r = -1; r < rv; r++)
for (int c = -1; c < cv; c++)
Rectangle rect = sheet.FpSpread.GetCellRectangle(r, c, rowIndex, columnIndex);
Please have a look at the attached sample for detailed implementation of the same.