Home - Forums-.NET - FlyGrid.Net (Windows Forms) - Custom stylist

FlyGrid.Net (Windows Forms)

.NET Datagrid - Fast, highly customizable, industry standards .NET data grid control for WinForms

This forum related to following products: FlyGrid.Net

Custom stylist
Link Posted: 19-Jun-2006 23:05
I'm writing a custom stylist for my grid.
I'm drawing the column headers myself now (back color and vertical separators) and this works fine. I've put a couple of properties in the stylist, so you can choose which colors you want for the headers in design-time.

Now I wanted to have another property in the custom stylist to set the foreground color (font color) of the headers. However, it seems that the text is drawn in the Grid-component, so it doesn't look like I can customize this in the stylist? I could set the foreground color of the grid (which I can access through StylistDrawInfo.Control) inside the Draw-function of the stylist when I need to redraw the headers, but won't this affect performance, since it will be doing this with every redraw? Are there other solutions?
Link Posted: 20-Jun-2006 01:11
Now I wanted to have another property in the custom stylist to set the foreground color (font color) of the headers. However, it seems that the text is drawn in the Grid-component, so it doesn't look like I can customize this in the stylist? I could set the foreground color of the grid (which I can access through StylistDrawInfo.Control) inside the Draw-function of the stylist when I need to redraw the headers, but won't this affect performance, since it will be doing this with every redraw? Are there other solutions?

Currently you can dynamically provide context dependent foreground colors of colum headers via Column object:
[c#]
public class ColoredHeaderColumn : Column
{
  //...
  public override Color ForeColor
  {
     get
     {
        return (State & ColumnState.MouseDown) != 0 ?
          SystemColors.Desktop :
          base.ForeColor;
     }
  }
}


or provide your own fore color (what you can set in Stylist without redrawing, currently painted Column instance is provided in StylistDrawInfo.Context):
[c#]
public class ColoredHeaderColumn : Column
{
  //...
  private Color myForeColor = Color.Empty;
  public override Color ForeColor
  {
     get
     {
        return !myForeColor.IsEmpty ?
          myForeColor :
          base.ForeColor;
     }
  }
  //to reset custom fore color and use standard ForeColor simply set it to Color.Empty
  public void SetMyOwnForeColorWithoutInvalidate(Color color)
  {
    myForeColor = color;
  }
}