找回密码
 立即注册

QQ登录

只需一步,快速开始

roger.wang
社区贡献组   /  发表于:2014-5-16 10:38  /   查看:4444  /  回复:0
问题描述:希望在单元格中同时添加文本和图片混排的方式。
问题解答:Spread提供了单元格自定义功能,可以继承ComoboCellType 并且重载PaintCell 方法来手动添加图片。
关键代码:
  

  1.    ///<summary>
  2.     ///通过继承 ComboCellType 实现
  3.     ///</summary>        
  4. public class ImageCombo : FarPoint.Win.Spread.CellType.ComboBoxCellType
  5.     {
  6. public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
  7.         {
  8.             if (value != null)
  9.             {
  10.                 int ind =0;
  11.             for (int i = 0; i <base.Items.Length; i++)
  12.             {
  13.             if (base.Items[i] == value.ToString())
  14.             {
  15.                 ind = i;
  16.                 break;
  17.             }
  18.          }
  19.             Image img = base.ImageList.Images[ind];
  20.             g.DrawImage(img, newRectangle(newPoint(r.X, r.Y), newSize(20, 20)));
  21.             g.DrawString(value.ToString(), appearance.Font, newSolidBrush(Color.Black), newPointF(r.X + 20, r.Y-10 + 10));
  22.             ControlPaint.DrawComboButton(g, newRectangle(r.Right - 17, r.Y, 17, r.Height), ButtonState.Normal);               
  23.             }
  24.             else
  25.             {
  26.                 base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);
  27.             }
  28.         }      
  29.     }
  30.   
复制代码
?
效果截图:


源码下载

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部