Spread.Net control provides a vast variety of CellTypes for different types of implementations in Spread. AnimatedCellType is one such CellType which is used for displaying animation in cell. To use this, we need to create a custom cell type inheriting from ImageCellType.

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:

  1. Paint cells using PaintCell() method

  2. Notify updation of the frame for painting using OnFrameChanged() method.

Paint Cells

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)
      lock (currentImage)
      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);
          if (!rect.IsEmpty)

Animated Cells in Spread.Net

Please have a look at the attached sample for detailed implementation of the same.