1金币
Spread for WinForms 教程资源集合贴中有“Spread:提示用户单元格内容长度超出了列宽"例子 打开自己的XML文件后,测试失败,当内容超出宽度后不显示#。
附件有我上传的DEMO。
请问如何修改可以达到例子中,超过宽度后显示#
private void Form1_Load(object sender, EventArgs e)
{
//fpSpread1.ActiveSheet.Cells[0, 0].Value = "12345679";
//fpSpread1.ActiveSheet.Cells[1, 0].Value = "12345679123456789123456789";
fpSpread1.Open(@"D:\bak\126.xml");
fpSpread1.ActiveSheet.Columns[0].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)
{
value = new string('#', value.ToString().Length);
}
base.PaintCell(g, r, appearance, value, isSelected, isLocked, zoomFactor);
}
}
|
|