I\'m writing a custom Button control as part of a (soon to be) free Control suite, and I would like to base my (default) Control colors on the corresponding Windows System color
There is a System Color Class out, which will provide you the Colors.
For WinForms use:
System.Drawing.SystemColors
For WPF use:
System.Windows.SystemColors
I am wanting the same thing. My approach is to, upon initialization, create a temporary window with the background color specified in GetSysColor(COLOR_BTNFACE), the "standard" background color for dialog boxes. Then, I create a button with no text and get the colors. This temporary window is never displayed, and is destroyed immediately (WM_CREATE exit code = -1).
You can use also the GetSysColor function api function.
Valter
You could use the Win API, GetSysColor function...
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int GetSysColor(int nIndex);
The function returns the red, green, blue (RGB) color value of the given element.
To display the component of the RGB value, use the GetRValue, GetGValue, and GetBValue macros.
System colors for monochrome displays are usually interpreted as shades of gray.
To paint with a system color brush, an application should use GetSysColorBrush(nIndex), instead of CreateSolidBrush(GetSysColor(nIndex)), because GetSysColorBrush returns a cached brush, instead of allocating a new one.
Yes. In fact, there is an entire class dedicated to this:
The SystemColors class.
...or for WPF (thanks @ORMapper), The System.Windows.SystemColors class.