不过有些时候,我们希望Spread的显示风格与您应用系统的显示风格保持一致,这时候我们就需要改变Spread中Outlines的显示样式,Spread也提供了这样的属性设置来改变Outlines的显示风格,比如通过下面的代码我们可以非常容易的实现自己的Outlines样式:
-
fpSpread1.ActiveSheet.Rows.Count = 11; fpSpread1.ActiveSheet.Columns.Count = 6; FarPoint.Win.Spread.EnhancedInterfaceRenderer outlinelook = new FarPoint.Win.Spread.EnhancedInterfaceRenderer(); outlinelook.RangeGroupBackgroundColor = Color.LightGreen; outlinelook.RangeGroupButtonBorderColor = Color.Red; outlinelook.RangeGroupLineColor = Color.Blue; fpSpread1.InterfaceRenderer = outlinelook; fpSpread1.ActiveSheet.AddRangeGroup(0, 8, true); fpSpread1.ActiveSheet.AddRangeGroup(0, 5, true); fpSpread1.ActiveSheet.AddRangeGroup(1, 3, false); fpSpread1.ActiveSheet.AddRangeGroup(1, 2, false); 复制代码
实现的效果如下:
当然,有时候我们希望实现更灵活的自定义功能,比如需要显示自己的“+”“-”,这时候我们就可以实现FarPoint.Win.Spread.IInterfaceRenderer接口,然后自己实现Outlines相关的显示风格
-
public class MyEnhancedInterfaceRenderer : FarPoint.Win.Spread.IInterfaceRenderer { FarPoint.Win.Spread.EnhancedInterfaceRenderer enhR = new FarPoint.Win.Spread.EnhancedInterfaceRenderer(); #region IInterfaceRenderer Members public void PaintRangeGroupButton(System.Drawing.Graphics g, int x, int y, int width, int height, FarPoint.Win.Spread.GroupState groupState, bool rowGroup, bool isLeftToRight) { // 在这里实现自定义Button的逻辑 if (groupState == FarPoint.Win.Spread.GroupState.Expanded) { g.DrawIcon(new Icon("Icon/Minus.ico"), new Rectangle(x, y, width, height)); } else if (groupState == FarPoint.Win.Spread.GroupState.Collapsed) { g.DrawIcon(new Icon("Icon/Plus.ico"), new Rectangle(x, y, width, height)); } //enhR.PaintRangeGroupButton(g, x, y, width, height, groupState, rowGroup, isLeftToRight); } #endregion } 复制代码
最终效果:
源码下载:VS2010 + Spread for WinForms 6.0