Get standard Windows system colors in .NET.

I am writing a Button user control as part of a free control pack (I will be soon), and I would like to base my (default) control colors on the corresponding colors of the Windows system. So, after searching for “Windows default system colors”, I could not find information about System Colors for Windows elements (especially not in Button controls).

Is there any way to get this color information (e.g. button border color, button color, button color, button color, button color, etc.) in .NET?

+6
source share
5 answers

Yes. In fact, there is a whole class for this:

Class SystemColors .

... or for WPF (thanks @ORMapper), class System.Windows.SystemColors .

+10
source

There is a color class system that will provide you with colors.

For WinForms use:

System.Drawing.SystemColors

For WPF use:

System.Windows.SystemColors

+8
source

You can also use the GetSysColor api function.

Walter

+2
source

You can use Win API, GetSysColor ...

[DllImport("user32.dll", CharSet=CharSet.Auto)] public static extern int GetSysColor(int nIndex); 

The function returns the color value of red, green, blue (RGB) of this element.

To display the RGB value component, use the GetRValue, GetGValue, and GetBValue macros.

The system colors for monochrome displays are usually interpreted as shades of gray.

To paint a system’s color brush, an application must use GetSysColorBrush (nIndex) instead of CreateSolidBrush (GetSysColor (nIndex)) because GetSysColorBrush returns a cached brush instead of selecting a new one.

+2
source

I want the same. My approach is to create a temporary window during initialization with the background color specified in GetSysColor (COLOR_BTNFACE), the "standard" background color for the dialog boxes. Then I create a button without text and get the colors. This time window is never displayed and is immediately destroyed (exit code WM_CREATE = -1).

0
source

Source: https://habr.com/ru/post/974637/


All Articles