Spread 表格控件提供了丰富的单元格类型。AnimatedCellType 是继承自 ImageCellType 单元格类型。
本篇文章将阐述如何实现动态图像单元格类型。我们需要创建自定义单元格类型来加载动态图片。
可以分两步实现:
1.使用 PaintCell() 方法,绘制单元格。
2.使用 OnFrameChanged() 刷新动态图片。
Paint Cells
这里会使用 .Net Framework’s ImageAnimator 类,以下方法将使图片每秒都变化一次。
1: public override void PaintCell(Graphics g, Rectangle r,
FarPoint.Win.Spread.Appearance appearance, object value,
bool isSelected, bool isLocked, float zoomFactor)
2: {
3: if (currentImage == null)
4: {
5: base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);
6: StartAnimate(value);
7: }
8: else lock (currentImage)
9: base.PaintCell(g, r, appearance, currentImage,
isSelected, isLocked, zoomFactor);
10: }
使用 OnFrameChanged() 刷新动态图片。
1: void OnFrameChanged(object sender, EventArgs e)
2: {
3: lock (currentImage)
4: ImageAnimator.UpdateFrames(currentImage);
5: int rv = sheet.FpSpread.GetRowViewportCount();
6: int cv = sheet.FpSpread.GetColumnViewportCount();
7: Rectangle spreadRect = sheet.FpSpread.Bounds;
8: for (int r = -1; r < rv; r++)
9: for (int c = -1; c < cv; c++)
10: {
11: Rectangle rect = sheet.FpSpread.GetCellRectangle(r, c, rowIndex, columnIndex);
12: rect.Intersect(spreadRect);
13: if (!rect.IsEmpty)
14: sheet.FpSpread.Invalidate();
15: }
16: }
Demo 下载:VS2010 + C# + Spread Studio 7 + .NET 4.0: 点击下载:
Demo 下载:VS2010 + VB.NET + Spread Studio 7 + .NET 4.0: 点击下载