Spread控件,系统默认提供的了2种选择器,分别通过配置属性即可实现。同时,我们也可自定义实现选择器。
- 系统选择器:
1: this.fpSpread1.SelectionRenderer = new FarPoint.Win.Spread.DefaultSelectionRenderer();
- 系统渐变选择器
1: FarPoint.Win.Spread.GradientSelectionRenderer gsr = new FarPoint.Win.Spread.GradientSelectionRenderer();
2: gsr.Color1 = Color.Green;
3: gsr.Color2 = Color.LightGreen;
4: gsr.LinearGradientMode = System.Drawing.Drawing2D.LinearGradientMode.Vertical;
5: gsr.Opacity = 100;
6: this.fpSpread1.SelectionRenderer = gsr;
- 系统选择器,修改颜色
1: fpSpread1.ActiveSheet.SelectionStyle = FarPoint.Win.Spread.SelectionStyles.SelectionColors;
2: fpSpread1.ActiveSheet.SelectionPolicy = FarPoint.Win.Spread.Model.SelectionPolicy.Range;
3: fpSpread1.ActiveSheet.SelectionUnit = FarPoint.Win.Spread.Model.SelectionUnit.Cell;
4: fpSpread1.ActiveSheet.SelectionBackColor = Color.Yellow;
5: fpSpread1.ActiveSheet.SelectionForeColor = Color.Green;
- 自定义选择器--渐变色
1:
2: fpSpread1.ActiveSheet.SelectionStyle = FarPoint.Win.Spread.SelectionStyles.SelectionRenderer;
3: SelectionRenderer_GradientSelection grd = new SelectionRenderer_GradientSelection(Color.Red, Color.PowderBlue, System.Drawing.Drawing2D.LinearGradientMode.Horizontal, 80);
4: this.fpSpread1.SelectionRenderer = grd;
5:
6: public class SelectionRenderer_GradientSelection : FarPoint.Win.Spread.GradientSelectionRenderer
7: {
8:
9: private Color clr1;
10:
11: private Color clr2;
12:
13: private System.Drawing.Drawing2D.LinearGradientMode gradMode;
14:
15: private int op;
16:
17: public SelectionRenderer_GradientSelection(Color color1, Color color2, System.Drawing.Drawing2D.LinearGradientMode mode, int opacity) :
18:
19: base(Color.Beige, Color.Blue, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal, 220)
20: {
21: clr1 = color1;
22: clr2 = color2;
23: gradMode = mode;
24: op = opacity;
25: }
26:
27: public new void PaintSelection(Graphics g, int x, int y, int width, int height)
28: {
29: if (((width > 0)
30: && (height < 0)))
31: {
32: Color c1 = Color.FromArgb(op, clr1.R, clr1.G, clr1.B);
33: Color c2 = Color.FromArgb(op, clr2.R, clr2.G, clr2.B);
34: LinearGradientBrush selectionBrush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(x, y, width, height), c1,
35: c2, gradMode);
36: g.FillRectangle(selectionBrush, x, y, width, height);
37: selectionBrush.Dispose();
38: }
39: }
40: }