问题描述:希望在单元格中同时添加文本和图片混排的方式。
问题解答:Spread提供了单元格自定义功能,可以继承ComoboCellType 并且重载PaintCell 方法来手动添加图片。
关键代码:
- ///<summary>
- ///通过继承 ComboCellType 实现
- ///</summary>
- public class ImageCombo : FarPoint.Win.Spread.CellType.ComboBoxCellType
- {
- public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
- {
- if (value != null)
- {
- int ind =0;
- for (int i = 0; i <base.Items.Length; i++)
- {
- if (base.Items[i] == value.ToString())
- {
- ind = i;
- break;
- }
- }
- Image img = base.ImageList.Images[ind];
- g.DrawImage(img, newRectangle(newPoint(r.X, r.Y), newSize(20, 20)));
- g.DrawString(value.ToString(), appearance.Font, newSolidBrush(Color.Black), newPointF(r.X + 20, r.Y-10 + 10));
- ControlPaint.DrawComboButton(g, newRectangle(r.Right - 17, r.Y, 17, r.Height), ButtonState.Normal);
- }
- else
- {
- base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);
- }
- }
- }
-
复制代码 ?
效果截图:
源码下载 |