There is a very handy .NET class called ControlPaint in the System.Windows.Forms namespace that enables you to draw your own controls and control elements using the standard Windows style and theme. Buried in this rich class are four methods that enable you to lighten and darken colors:
- Dark – Creates a darker color from the specified color.
- DarkDark – Creates a much darker color.
- Light – Creates a lighter color.
- LightLight – Creates a much lighter color.
All four static methods accept a Color structure argument and return the new Color. The Dark and Light methods are overloaded and can also accept a floating point percentage of their respective DarkDark or LightLight colors, where 1.0 equals 100%:
public static Color Dark( Color baseColor )
public static Color Dark( Color baseColor, float pctOfDarkDark )
public static Color DarkDark( Color baseColor )
public static Color Light( Color baseColor )
public static Color Light( Color baseColor, float pctOfLightLight )
public static Color LightLight( Color baseColor )
This image demonstrates these methods on the Color.Red:
There are some interesting aspects to these methods:
- Dark( color, 0.5F ) == Dark( color )
- Dark( color, 1.0F ) == DarkDark( color )
- Dark( color, 1.0F ) == Color.Black
- Light( color, 0.5F ) == Light( color )
- Light( color, 1.0F ) == LightLight( color )
- Light( color, 2.0F ) == Color.White
- If the specified Color is one of the SystemColors, the color is converted to the SystemColors.ControlDark color (or ControlDarkDark, ControlLight or ControlLightLight system color as appropriate). Otherwise, the color’s luminosity value is increased or decreased by the percentage specified.