Spread for WinForms 表格控件兼容Excel的强大功能,并将其嵌入到您的应用系统中。完备的Excel文档支持使得您可以在企业中分享和访问数据信息。在日常工作中我们经常需要比较不同年份数据或两个结构相同表格之间的数据差异。这种功能即要求使两个 Spread 联动,本文即将阐述如何实现此功能。
下面分布阐述:
1.定制 Spread 垂直滚动条,实现垂直方向联动:
1: fpSpread1.TopChange += new TopChangeEventHandler(fpSpread1_TopChange);
2:
3: void fpSpread1_TopChange(object sender, TopChangeEventArgs e)
4: {
5: fpSpread2.SetViewportTopRow(0, e.NewTop);
6: }
2.定制 Spread 水平滚动条,实现水平方向联动:
1: fpSpread1.LeftChange += new LeftChangeEventHandler(fpSpread1_LeftChange);
2:
3: void fpSpread1_LeftChange(object sender, LeftChangeEventArgs e)
4: {
5: fpSpread2.SetViewportLeftColumn(0, e.NewLeft);
6: }
3.定制单元格选择样式:
1: public class SelectionRenderer : FarPoint.Win.Spread.GradientSelectionRenderer
2: {
3:
4: private Color clr1;
5:
6: private Color clr2;
7:
8: private System.Drawing.Drawing2D.LinearGradientMode gradMode;
9:
10: private int op;
11:
12: public SelectionRenderer(Color color1, Color color2,
System.Drawing.Drawing2D.LinearGradientMode mode, int opacity) :
13:
14: base(Color.Beige,
Color.Blue, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal, 220)
15: {
16: clr1 = color1;
17: clr2 = color2;
18: gradMode = mode;
19: op = opacity;
20: }
21:
22: public new void PaintSelection(Graphics g,
int x, int y, int width, int height)
23: {
24: if (((width > 0) && (height > 0)))
25: {
26: Color c1 = Color.FromArgb(op, clr1.R, clr1.G, clr1.B);
27: Color c2 = Color.FromArgb(op, clr2.R, clr2.G, clr2.B);
28: System.Drawing.Drawing2D.LinearGradientBrush selectionBrush =
new System.Drawing.Drawing2D.LinearGradientBrush
(new Rectangle(x, y, width, height), c1,
29: c2, gradMode);
30: g.FillRectangle(selectionBrush, x, y, width, height);
31: g.Dispose();
32: }
33: }
34: }
效果图:
Demo 下载:编辑环境 VS2010 && Spread for Winforms 7.0 && C# 点击下载