We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to create the custom themes and apply to the WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: April 30, 2011 |
Last Revised Date: December 19, 2019
Tags: custom, themes

Customizing visual styles

To create a custom theme, you need to create an object that supports the IVisualStyle interface. After implementing the custom object, you can set the GridVisualStylesDrawing object for the Grid. The attached sample has the customization of the Grid header style.

Creating Custom Visual Style:

The following code example changes the blue header style to pink header style and orange hover color to green hover color by modifying the code from the libraries GridVisualStylesOffice2007Blue class.

C#

public class CustomTheme : IVisualStylesDrawing
{
    private GridVisualStyles visualStyle;
    //Creates a new instance of the CustomTheme class.
    public CustomTheme(GridVisualStyles style)
    {
        this.visualStyle = style;
    }
public void DrawHeaderStyle(Graphics g, Rectangle rect, ThemedHeaderDrawing.HeaderState state)
{            
    //Checks the empty headers
    if (rect.Height == 0 && rect.Width == 0)
        return;
    //Checks the current state of the header and paints the foreground accordingly.
    if (state == ThemedHeaderDrawing.HeaderState.Normal)
    {
        LinearGradientBrush br = new LinearGradientBrush(rect, Color.FromArgb(255, 128, 255), Color.FromArgb(255, 0, 128), LinearGradientMode.Vertical);                     
        g.FillRectangle(br, new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2));
        br.Dispose();
    }            
    else
    {               
        LinearGradientBrush br = new LinearGradientBrush(rect, Color.FromArgb(0, 128, 0), Color.FromArgb(128, 255, 128), LinearGradientMode.Vertical);
        g.FillRectangle(br, new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2));
        br.Dispose();
    }
}
//IVisualStylesDrawing Members…
}

 

VB

Public Class CustomTheme 
 Implements IVisualStylesDrawing
 Private visualStyle As GridVisualStyles
 'Creates a new instance of the CustomTheme class.
 Public Sub New(ByVal style As GridVisualStyles)
  Me.visualStyle = style
 End Sub
Public Sub DrawHeaderStyle(ByVal g As Graphics, ByVal rect As Rectangle, ByVal state As ThemedHeaderDrawing.HeaderState)
 'Checks the empty headers
 If rect.Height = 0 AndAlso rect.Width = 0 Then
  Return
 End If
 'Checks the current state of the header and paints the foreground accordingly.
 If state Is ThemedHeaderDrawing.HeaderState.Normal Then
  Dim br As New LinearGradientBrush(rect, Color.FromArgb(255, 128, 255), Color.FromArgb(255, 0, 128), LinearGradientMode.Vertical)
  g.FillRectangle(br, New Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2))
  br.Dispose()
 Else
  Dim br As New LinearGradientBrush(rect, Color.FromArgb(0, 128, 0), Color.FromArgb(128, 255, 128), LinearGradientMode.Vertical)
  g.FillRectangle(br, New Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2))
  br.Dispose()
 End If
End Sub
'IVisualStylesDrawing Members…
End Class

Adding the Custom Theme to the GridControl

C#

//Plugs in any custom GridVisualStyle
this.gridControl1.GridVisualStyles = GridVisualStyles.Custom;
this.gridControl1.Model.Options.GridVisualStylesDrawing = new CustomThemes(GridVisualStyles.Custom);

 

VB

' Plugs in any custom GridVisualStyle
Me.gridControl1.GridVisualStyles = GridVisualStyles.Custom
Me.gridControl1.Model.Options.GridVisualStylesDrawing = New CustomThemes(GridVisualStyles.Custom)

The following screenshot displays the GridControl with the applied custom themes.

Applied custom themes to GridControl

Samples:

C#: CustomThemes-C#-1025057269.zip

VB: CustomThemes-VB-943074265.zip

Reference link: https://help.syncfusion.com/windowsforms/grid-control/visual-styles

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon