You can customize renderers in Spread Windows Forms. The renderers are used in headers, corners, cells, and other areas. You can also customize the renderers used to create the styles in Spread Windows Forms. This can be useful if you want to create a specific style for your application.

The default style uses the ColumnHeaderDefaultEnhanced, CornerDefaultEnhanced, CornerFooterDefaultEnhanced, FilterBarDefaultEnhanced, and RowHeaderDefaultEnhanced fields.

The Office2013 or Office2016 style uses the FlatCornerHeaderRenderer, FlatColumnHeaderRenderer, FlatRowHeaderRenderer, FlatScrollBarRenderer, and FlatFocusIndicatorRenderer classes.

The Office2007 style uses the EnhancedCornerRenderer, EnhancedFocusIndicatorRenderer, EnhancedColumnHeaderRenderer, EnhancedScrollBarRenderer, and EnhancedRowHeaderRenderer classes.

The classic style uses the ColumnHeaderRenderer, RowHeaderRenderer, and CornerRenderer classes.

The following example customizes the renderers for the column header and footer, row header, corner header, and corner footer.

Custom Renderers


C#
//header/footer column
fpSpread1.ActiveSheet.ColumnFooter.Visible = true;
fpSpread1.ActiveSheet.ColumnFooter.RowCount = 3;
fpSpread1.ActiveSheet.ColumnHeader.RowCount = 3;
//Create a new renderer and set the renderer properties.
FarPoint.Win.Spread.CellType.FlatColumnHeaderRenderer flatcolumnheader = new FarPoint.Win.Spread.CellType.FlatColumnHeaderRenderer();
flatcolumnheader.NormalBackgroundColor = Color.Orchid;
fpSpread1.ActiveSheet.ColumnHeader.DefaultStyle.Renderer = flatcolumnheader;
FarPoint.Win.Spread.CellType.FlatColumnFooterRenderer flatcolumnfooter = new FarPoint.Win.Spread.CellType.FlatColumnFooterRenderer();
flatcolumnfooter.GridLineNormalColor = Color.Gold;
//Set the renderer for the default style area such as column footer.
fpSpread1.ActiveSheet.ColumnFooter.DefaultStyle.Renderer = flatcolumnfooter;
//header row
fpSpread1.ActiveSheet.RowHeader.ColumnCount = 3;
FarPoint.Win.Spread.CellType.FlatRowHeaderRenderer flatrowheader = new FarPoint.Win.Spread.CellType.FlatRowHeaderRenderer();
flatrowheader.NormalBackgroundColor = Color.Gray;
fpSpread1.ActiveSheet.RowHeader.DefaultStyle.Renderer = flatrowheader;
//sheet corner header render
FarPoint.Win.Spread.CellType.FlatCornerHeaderRenderer flatcornerheader = new FarPoint.Win.Spread.CellType.FlatCornerHeaderRenderer();
flatcornerheader.NormalTriangleColor = Color.Yellow;
fpSpread1.ActiveSheet.SheetCorner.DefaultStyle.Renderer = flatcornerheader;
//sheet corner footer render
FarPoint.Win.Spread.SpreadSkin a1 = new FarPoint.Win.Spread.SpreadSkin(FarPoint.Win.Spread.DefaultSpreadSkins.Default);
a1.Apply(fpSpread1);
fpSpread1.ActiveSheet.ColumnFooter.Visible = true;
FarPoint.Win.Spread.CellType.FlatCornerFooterRenderer flatcornerfooter = new FarPoint.Win.Spread.CellType.FlatCornerFooterRenderer();
flatcornerfooter.NormalTriangleColor = Color.Aquamarine;
FarPoint.Win.Spread.NamedStyle corner = new FarPoint.Win.Spread.NamedStyle("corner", "HeaderDefault");
corner.BackColor = Color.Olive;
corner.Renderer = flatcornerfooter;
//Apply the new corner styles to the control.
fpSpread1.NamedStyles.Add(corner);
a1.CornerFooterDefaultStyle = corner;

VB
'header/footer column
FpSpread1.ActiveSheet.ColumnFooter.Visible = True
FpSpread1.ActiveSheet.ColumnFooter.RowCount = 3
FpSpread1.ActiveSheet.ColumnHeader.RowCount = 3
'Create a new renderer and set the renderer properties.
Dim flatcolumnheader As New FarPoint.Win.Spread.CellType.FlatColumnHeaderRenderer()
flatcolumnheader.NormalBackgroundColor = Color.Orchid
FpSpread1.ActiveSheet.ColumnHeader.DefaultStyle.Renderer = flatcolumnheader
Dim flatcolumnfooter As New FarPoint.Win.Spread.CellType.FlatColumnFooterRenderer()
flatcolumnfooter.GridLineNormalColor = Color.Gold
'Set the renderer for the default style area such as column footer.
FpSpread1.ActiveSheet.ColumnFooter.DefaultStyle.Renderer = flatcolumnfooter
'header row
FpSpread1.ActiveSheet.RowHeader.ColumnCount = 3
Dim flatrowheader As New FarPoint.Win.Spread.CellType.FlatRowHeaderRenderer()
flatrowheader.NormalBackgroundColor = Color.Gray
FpSpread1.ActiveSheet.RowHeader.DefaultStyle.Renderer = flatrowheader
'sheet corner header render
Dim flatcornerheader As New FarPoint.Win.Spread.CellType.FlatCornerHeaderRenderer()
flatcornerheader.NormalTriangleColor = Color.Yellow
FpSpread1.ActiveSheet.SheetCorner.DefaultStyle.Renderer = flatcornerheader
'sheet corner footer render
Dim a1 As New FarPoint.Win.Spread.SpreadSkin(FarPoint.Win.Spread.DefaultSpreadSkins.Default)
a1.Apply(FpSpread1)
FpSpread1.ActiveSheet.ColumnFooter.Visible = True
Dim flatcornerfooter As New FarPoint.Win.Spread.CellType.FlatCornerFooterRenderer()
flatcornerfooter.NormalTriangleColor = Color.Aquamarine
Dim corner As New FarPoint.Win.Spread.NamedStyle("corner", "HeaderDefault")
corner.BackColor = Color.Olive
corner.Renderer = flatcornerfooter
'Apply the new corner styles to the control.
FpSpread1.NamedStyles.Add(corner)
a1.CornerFooterDefaultStyle = corner

You can customize the corner renderer, which draws the sheet corner.

There are two pre-defined corner renderers in Spread.

The default renderer draws the sheet corner with or without the Windows XP style depending on the setting of the system. The enhanced corner renderer always draws the sheet corner with an appearance similar to Microsoft Excel 2007.

This example lists the methods that are used to create a custom corner renderer.

C#
public class MyCornerRenderer : IRenderer {
public Size GetPreferredSize(Graphics g, Size size, Appearance appearance, object value, float zoomFactor)
{
///Your code here
}
public virtual void PaintCell(Graphics g, Rectangle r, Appearance appearance, object value, bool isSelected, bool isLocked, float zoomFactor)
{
///Your code here
}
public virtual void PaintCorner(Graphics g, Rectangle r, Color backColor, Color foreColor, Font f, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, string s, TextOrientation textOrientation, bool wordWrap, HotkeyPrefix hotkeyPrefix, StringTrimming stringTrim, VisualStyles visualStyles, bool mouseOver, bool rightToLeft, float zoomFactor)
{
///Your code here
}
public bool CanOverflow()
{
///Your code here
}
public bool CanBeOverflown()
{
///Your code here
}
}
// Assign new corner render to draw sheet corner:
fpSpread1.ActiveSheet.SheetCornerStyle.Renderer = new MyCornerRenderer();

This example creates a custom corner renderer.

C#
public class MyCornerRenderer : FarPoint.Win.Spread.CellType.IRenderer
{
public bool CanOverflow() { return true; }
public bool CanBeOverflown() { return true; }
public virtual void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appear, object value, bool issel, bool isl, float zoom) {
g.FillRectangle(Brushes.Green, 0, 0, 30, 30);
}
public Size GetPreferredSize(Graphics g, Size size, FarPoint.Win.Spread.Appearance appear, object value, float zoomFactor)
{
size = new Size(10, 10);
return size;
}
}

private void Form1_Load(object sender, EventArgs e)
{
fpSpread1.ActiveSheet.SheetCornerStyle.Renderer = new MyCornerRenderer();
}

VB
Public Class MyCornerRenderer
Implements FarPoint.Win.Spread.CellType.IRenderer

Public Sub PaintCell(g As Graphics, r As Rectangle, appearance As FarPoint.Win.Spread.Appearance, value As Object, isSelected As Boolean, isLocked As Boolean, zoomFactor As Single) Implements FarPoint.Win.Spread.CellType.IRenderer.PaintCell
g.FillRectangle(Brushes.Green, 0, 0, 30, 30)
End Sub

Public Function CanBeOverflown() As Boolean Implements FarPoint.Win.Spread.CellType.IRenderer.CanBeOverflown
Return True
End Function

Public Function CanOverflow() As Boolean Implements FarPoint.Win.Spread.CellType.IRenderer.CanOverflow
Return True
End Function

Public Function GetPreferredSize(g As Graphics, size As Size, appear As FarPoint.Win.Spread.Appearance, value As Object, zoomFactor As Single) As Size Implements FarPoint.Win.Spread.CellType.IRenderer.GetPreferredSize
size = New Size(10, 10)
Return size
End Function
End Class

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FpSpread1.ActiveSheet.SheetCornerStyle.Renderer = New MyCornerRenderer()
End Sub

This example sets colors for the enhanced corner renderer.

Corner Renderer


C#
FarPoint.Win.Spread.CellType.EnhancedCornerRenderer rend = new FarPoint.Win.Spread.CellType.EnhancedCornerRenderer(Color.Bisque, Color.Tomato, Color.Maroon);
fpSpread1.ActiveSheet.SheetCorner.DefaultStyle.Renderer = rend;
fpSpread1.ActiveSheet.AllowTableCorner = true;

VB
Dim rend As New FarPoint.Win.Spread.CellType.EnhancedCornerRenderer(Color.Bisque, Color.Tomato, Color.Maroon)
FpSpread1.ActiveSheet.SheetCorner.DefaultStyle.Renderer = rend
FpSpread1.ActiveSheet.AllowTableCorner = True

This example sets the background color for the flat column header renderer.

C#
FarPoint.Win.Spread.CellType.FlatColumnHeaderRenderer flatcolumnheader = new FarPoint.Win.Spread.CellType.FlatColumnHeaderRenderer();
flatcolumnheader.NormalBackgroundColor = Color.Bisque;
fpSpread1.ActiveSheet.ColumnHeader.DefaultStyle.Renderer = flatcolumnheader;

VB
Dim flatcolumnheader As New FarPoint.Win.Spread.CellType.FlatColumnHeaderRenderer()
flatcolumnheader.NormalBackgroundColor = Color.Bisque
FpSpread1.ActiveSheet.ColumnHeader.DefaultStyle.Renderer = flatcolumnheader

This example creates a custom corner renderer.

Custom Corner Renderer


C#
public class MyCornerRenderer : FarPoint.Win.Spread.CellType.CornerRenderer
{
public override void PaintCorner(Graphics g, Rectangle r, Color c, Color back, Font f, FarPoint.Win.HorizontalAlignment halign, FarPoint.Win.VerticalAlignment valign, string s, FarPoint.Win.TextOrientation to, bool wordwrap, System.Drawing.Text.HotkeyPrefix hk, StringTrimming st, FarPoint.Win.VisualStyles vs, bool mouseover, bool rtl, float zf)
{
c = Color.Red;
back = Color.Aqua;
f = new Font("Arial", 10);
halign = FarPoint.Win.HorizontalAlignment.Center;
hk = System.Drawing.Text.HotkeyPrefix.None;
valign = FarPoint.Win.VerticalAlignment.Center;
to = FarPoint.Win.TextOrientation.TextHorizontal;
wordwrap = true;
s = "C";
st = StringTrimming.None;
vs = FarPoint.Win.VisualStyles.Off;
mouseover = false;
rtl = false;
zf = 0.5F;
base.PaintCorner(g, r, c, back, f, halign, valign, s, to, wordwrap, hk, st, vs, mouseover, rtl, zf);
}
}

private void Form1_Load(object sender, EventArgs e)
{
fpSpread1.ActiveSheet.SheetCornerStyle.Renderer = new MyCornerRenderer();
}

VB
Public Class MyCornerRenderer
Inherits FarPoint.Win.Spread.CellType.CornerRenderer

Public Overrides Sub PaintCorner(g As Graphics, r As Rectangle, c As Color, back As Color, f As Font, halign As FarPoint.Win.HorizontalAlignment,
valign As FarPoint.Win.VerticalAlignment, s As String, tor As FarPoint.Win.TextOrientation, wordwrap As Boolean, hk As System.Drawing.Text.HotkeyPrefix, sf As StringTrimming, vs As FarPoint.Win.VisualStyles, mouseover As Boolean, rtl As Boolean, zf As Single)

c = Color.Red
back = Color.Aqua
f = New Font("Arial", 10)
halign = FarPoint.Win.HorizontalAlignment.Center
hk = System.Drawing.Text.HotkeyPrefix.None
valign = FarPoint.Win.VerticalAlignment.Center
tor = FarPoint.Win.TextOrientation.TextHorizontal
wordwrap = True
s = "C"
sf = StringTrimming.None
vs = FarPoint.Win.VisualStyles.Off
mouseover = False
rtl = False
zf = 0.5F
MyBase.PaintCorner(g, r, c, back, f, halign, valign, s, tor, wordwrap, hk, sf, vs, mouseover, rtl, zf)
End Sub
End Class

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FpSpread1.ActiveSheet.SheetCornerStyle.Renderer = New MyCornerRenderer()
End Sub

This example implements the IRenderer interface and creates a custom renderer for the first cell in the spreadsheet.

Cell Renderer


C#
public static CheckBox ck = new CheckBox();
class MyRenderer : FarPoint.Win.Spread.CellType.IRenderer
{
public bool CanOverflow()
{
return true;
}
public bool CanBeOverflown()
{
return true;
}
public Size GetPreferredSize(Graphics g, Size s, FarPoint.Win.Spread.Appearance appr, object value, float zoom)
{
s = new Size(50, 50);
return s;
}
public void PaintCell(Graphics g, Rectangle r, FarPoint.Win.Spread.Appearance appr, object value, bool issel, bool islocked,
float zoom)
{
string s;
ck.CheckState = CheckState.Checked;
s = ck.CheckState.ToString();
Font f = new Font("MS Sans Serif", 10);
appr.BackColor = Color.Red;
appr.ForeColor = Color.Yellow;
appr.Font = f;
Brush b, b1;
b = new SolidBrush(appr.BackColor);
b1 = new SolidBrush(appr.ForeColor);
g.FillRectangle(b, r);
g.DrawString(s, appr.Font, b1, r);
b.Dispose();
b1.Dispose();
}
}

private void Form1_Load(object sender, EventArgs e)
{
fpSpread1.ActiveSheet.Cells[0, 0].Renderer = new MyRenderer();
}

VB
Shared ck As New CheckBox()

Public Class MyRenderer
Implements FarPoint.Win.Spread.CellType.IRenderer

Public Function CanBeOverflown() As Boolean Implements FarPoint.Win.Spread.CellType.IRenderer.CanBeOverflown
Return True
End Function

Public Function CanOverflow() As Boolean Implements FarPoint.Win.Spread.CellType.IRenderer.CanOverflow
Return True
End Function

Public Function GetPreferredSize(ByVal g As Graphics, ByVal s As Size, ByVal appr As FarPoint.Win.Spread.Appearance, ByVal value As Object, ByVal zoom As Single) As Size Implements FarPoint.Win.Spread.CellType.IRenderer.GetPreferredSize
s = New Size(50, 50)
Return s
End Function

Public Sub PaintCell(ByVal g As Graphics, ByVal r As Rectangle, ByVal appr As FarPoint.Win.Spread.Appearance, ByVal Value As Object, ByVal issel As Boolean, ByVal islocked As Boolean, ByVal zoom As Single) Implements FarPoint.Win.Spread.CellType.IRenderer.PaintCell
Dim s As String
ck.CheckState = CheckState.Checked
s = ck.CheckState.ToString()
Dim f As New Font("MS Sans Serif", 10)
appr.BackColor = Color.Red
appr.ForeColor = Color.Yellow
appr.Font = f
Dim b, b1 As Brush
b = New SolidBrush(appr.BackColor)
b1 = New SolidBrush(appr.ForeColor)
g.FillRectangle(b, r)
g.DrawString(s, appr.Font, b1, r.X, r.Y)
b.Dispose()
b1.Dispose()
End Sub

End Class
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
FpSpread1.ActiveSheet.Cells(0, 0).Renderer = New MyRenderer()
End Sub