Get default Windows System Colors in .NET

前端 未结 5 1750
闹比i
闹比i 2021-02-14 07:49

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

5条回答
  •  一向
    一向 (楼主)
    2021-02-14 08:41

    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.

提交回复
热议问题