Ever wondered about gradient title bars when using Windows Forms?
I have definitely wanted to get access to the gradient title colors a number of times. I'm sure some people have gone out and written their own calls to get these, but others I'm betting haven't. Out of all system colors, only two don't show up in the KnownColors and therefore SystemColors areas of System.Drawing. These happen to be GradientActiveCaption and GradientInactiveCaption. I'm including some source below that grabs colors just for these two items. You could probably do some work and have them automatically create linear gradient brushes too, but I'm not going to do all of the work for yah.
using System;
using System.Drawing;
using System.Runtime.InteropServices;
public class SystemGradientColors {
[DllImport("user32.dll")]
private static extern int GetSysColor(int nIndex);
// Constants for gradient colors
private const int COLOR_GRADIENTACTIVECAPTION = 27;
private const int COLOR_GRADIENTINACTIVECAPTION = 28;
private static Color colorGradientActiveCaption = Color.Empty;
private static Color colorGradientInactiveCaption = Color.Empty;
public static Color GradientActiveCaption {
get {
if ( colorGradientActiveCaption == Color.Empty ) {
int color = GetSysColor(COLOR_GRADIENTACTIVECAPTION);
colorGradientActiveCaption = FromWin32Value(color);
}
return colorGradientActiveCaption;
}
}
public static Color GradientInactiveCaption {
get {
if ( colorGradientInactiveCaption == Color.Empty ) {
int color = GetSysColor(COLOR_GRADIENTINACTIVECAPTION);
colorGradientInactiveCaption = FromWin32Value(color);
}
return colorGradientInactiveCaption;
}
}
private static Color FromWin32Value(int value) {
return Color.FromArgb(value & 0xFF, (value >> 8) & 0xFF, (value >> 16) & 0xFF);
}
}