回复 1楼sakeryu的帖子
一个很实际的需求,请参考以下代码:
- private void Form2_Load(object sender, EventArgs e)
- {
- fpSpread1.ActiveSheet.DefaultStyle.CellType = new CCellType();
- }
- public class CCellType : FarPoint.Win.Spread.CellType.TextCellType
- {
- public override void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
- {
- // 判断单元格内容是否为空,如果不为空就判断单元格内容是否超过了单元格的宽带
- if (value != null && g.MeasureString(value.ToString(),appearance.Font).Width > r.Width)
- {
- // 计算应该填充的 # 的数量
- StringBuilder sb = new StringBuilder("");
- while (g.MeasureString(sb.ToString(),appearance.Font).Width < r.Width)
- {
- sb.Append("#");
- }
- value = sb.ToString();
- }
- base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);
- }
- }
复制代码 |