最终运行效果:
Spread添加ToolTip功能,FpSpread类型提供了TextTipAppearance、TextTipDelay和TextTipPolicy属性来设置ToolTip
TextTipAppearance:主要通过TipAppearance类型来设置ToolTip的显示外观
TextTipDelay:设置延迟多久之后显示ToolTip,时间单位是毫秒
TextTipPolicy:设置显示ToolTip显示的时机
private void Form1_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add("编码"); dt.Columns.Add("名称"); dt.Columns.Add("售价"); dt.Rows.Add("AC23658901", "法国水果沙拉", "98"); dt.Rows.Add("AC23658902", "印度鸡排咖喱饭", "26"); dt.Rows.Add("AC23658903", "必胜客豪华套餐", "158"); FarPoint.Win.Spread.TipAppearance app = new FarPoint.Win.Spread.TipAppearance(); app.BackColor = Color.Yellow; app.Font = new Font("Comic Sans MS", 12); app.ForeColor = Color.Red; fpSpread1.DataSource = dt; fpSpread1.TextTipPolicy = FarPoint.Win.Spread.TextTipPolicy.Floating; fpSpread1.TextTipAppearance = app; fpSpread1.TextTipDelay = 1000; fpSpread1.TextTipPolicy = FarPoint.Win.Spread.TextTipPolicy.Floating; } 复制代码
移到单元格之后,并没有显示ToolTip,原因是Spread默认单元格内容超过单元格宽度时才显示ToolTip,不过我们可以通过Spread提供TextTipFetch事件来改变这一默认行为:
-
private void fpSpread1_TextTipFetch(object sender, FarPoint.Win.Spread.TextTipFetchEventArgs e) { e.ShowTip = true; // 除此之外,还可以根据参数 e 的各个属性值来实现自定义更强的ToolTip功能 } 复制代码
这样我们就可以正常的显示ToolTip,此外,我们还可以根据TextTipFetch事件中参数 e 的属性值来实现更多的自定义显示功能。
源码下载:
VS2010 + Spread for WinForms 6.0